开发者

Joining a NSArray of objects into a string, but need to be able to specify property

开发者 https://www.devze.com 2023-01-09 12:28 出处:网络
I have a NSArray of Foo objects. @interface Foo : NSObject { } - (NSString *) name; @end I want to be able to join all these [Foo name] results into one NSString.

I have a NSArray of Foo objects.

 @interface Foo : NSObject
 {
 }
 - (NSString *) name;
 @end

I want to be able to join all these [Foo name] results into one NSString.

In C# I would get a array of these by using LINQ, creating a Array of it, and feeding it to String.Join():

 List<Foo> foo = [..];
 String.Join(",", foo.select(F => F.name()).ToArray());

Is something开发者_运维百科 like this possible in Objective-C?

I know about [NSArray componentsJoinedByString], but how would I just easily select the [Foo name] properties of all the objects without manually looping trough its contents?


[[myArray valueForKey:@"name"] componentsJoinedByString:@","]

(docs)

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号