Convert NSArray to NSString in Objective-C

后端 未结 9 1288
难免孤独
难免孤独 2020-11-28 01:13

I am wondering how to convert an NSArray [@\"Apple\", @\"Pear \", 323, @\"Orange\"] to a string in Objective-C.

9条回答
  •  情歌与酒
    2020-11-28 01:27

    NSArray *array = [NSArray arrayWithObjects:@"One",@"Two",@"Three", nil];
    NSString *stringFromArray = [array componentsJoinedByString:@" "];
    

    The first line initializes an array with objects. The second line joins all elements of that array by adding the string inside the "" and returns a string.

提交回复
热议问题