How to convert NSArray to NSString

How to convert NSArray to NSString in objective-c?

+7
objective-c iphone nsstring nsarray
source share
4 answers

Whereas you are not saying that in NSArray, you can do this:

NSArray *arr = [NSArray arrayWithObjects: @"foo", @"bar", @"baz"]; [arr componentsJoinedByString: @","] 
+28
source share

Unlike Frank's method, which works very well, you can also do

 NSString *myArrayString = [array description]; 

By default, the NSArray implementation will print the contents in neatly formatted form.

+12
source share

This is how I 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]; 
+4
source share

Latest Swift 3.0 Updates

let string = array.componentsJoined(by: ",")

you can use any separator in the function that you want to separate from the array elements in the above example - ",".

0
source share

All Articles