Objective-C Simplest way to create comma separated string from an array of objects

arrays, nsmutablearray, objective-c, swift

Solution

Use the `NSArray` instance method `componentsJoinedByString:`.

In Objective-C:

- (NSString *)componentsJoinedByString:(NSString *)separator

In Swift:

func componentsJoinedByString(separator: String) -> String

Example:

In Objective-C:

NSString *joinedComponents = [array componentsJoinedByString:@","];

In Swift:

let joinedComponents = array.joined(seperator: ",")

Problem

So I have a nsmutablearray with a bunch of objects in it. I want to create a comma separated string of the id value of each object.

Original source