Reputation: 294
How to convert NSArray into NSString in objective-c?
Upvotes: 9
Views: 24305
Reputation: 332
Swift 3.0 latest updates
let string = array.componentsJoined(by: ",")
you can used any separator in function which you want to separate the array elements currently in above example is ",".
Upvotes: 1
Reputation: 41
This is how I have converted my NSArray
to NSString
NSError *error = nil;
NSData *data = [NSJSONSerialization dataWithJSONObject:aArray options:kNilOptions error:&error];
NSString *str = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
Upvotes: 4
Reputation: 58458
Aternatively to Frank's method, which works pretty well, you could also do
NSString *myArrayString = [array description];
The default implementation of description on NSArray will print out the contents in a neatly formatted fashion.
Upvotes: 12
Reputation: 17132
Bearing in mind that you don't say what's in the NSArray, you can do this:
NSArray *arr = [NSArray arrayWithObjects: @"foo", @"bar", @"baz"];
[arr componentsJoinedByString: @","]
Upvotes: 29