开发者

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

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜