views:

41

answers:

1

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?

+6  A: 
[[myArray valueForKey:@"name"] componentsJoinedByString:@","]

(docs)

cobbal
Yup -- though I believe OP wants it joined by `@","` or `@", "`.
bbum
@bbum yep, just saw and fixed
cobbal