How to convert NSArray into NSString

天涯浪子 提交于 2019-11-29 00:09:58

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: @","]

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.

TheGreen

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];
Chavda jaydeep

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 ",".

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!