iOS String to Array Conversion Guide

In iOS, you can use the componentsSeparatedByString method of NSString to convert a string into an array. The specific code is as follows:

NSString *str = @"apple,orange,banana";
NSArray *array = [str componentsSeparatedByString:@","];
NSLog(@"%@", array);

By running the code above, the output result will be:

(
    apple,
    orange,
    banana
)

The string “apple, orange, banana” is about to be transformed into an array with three elements.

bannerAds