Capturing a specific array element in Objective-C

I split the line into ';', but I want to specifically capture the first and second elements.

I know that PHP is just just $ array [0], just can't find anything for this for Objective-C

NSArray *tempArray = [returnString componentsSeparatedByString:@";"]; 

So here I have assigned my array, how can I get the first and second elements?

+6
source share
3 answers

Just simple [array objectAtIndex:0] in Objective-C; -)

+13
source

Starting with Xcode 4.5 (and Clang 3.3), you can use Objective-C Literals :

 NSString *tmpString1 = tempArray[1]; 
+2
source
 NSString *tmpString = [tempArray objectAtIndex:0]; NSLog(@"String at index 0 = %@", tmpString); NSString *tmpString1 = [tempArray objectAtIndex:1]; NSLog(@"String at index 1 = %@", tmpString1); 

You can also do an IF statement to verify that tmpArray actually contains objects before trying to capture its value ...

eg.

if ([tempArray count]> = 2) {

// do the following ...

}

+1
source

Source: https://habr.com/ru/post/898370/


All Articles