Tutorial :array index for iphone



Question:

 NSString *list = @"Norman, Stanley, Fletcher";  NSMutableArray *a2 = [[NSMutableArray alloc] init];  //a2= [list componentsSeparatedByString:@", "];      [a2 addObject:list];  //NSArray *listItems = [list componentsSeparatedByString:@", "];    NSLog(@"array is  %@",a2);  NSLog(@"array o  %@",a2[0]);  

how to get a2[0]=Norman , a2[1]=stanley???


Solution:1

Trying this

   NSArray *listItems = [list componentsSeparatedByString:@", "];     [a2 addObject:list];      NSLog(@"array o  %@", [a2 objectAtIndex:0]);  


Solution:2

When you create a mutable array you have to add objects to the array. You can't set the mutable array equal to a normal array (its returned by componentsSeparatedByString:)

  NSString *list = @"Norman, Stanley, Fletcher";  NSMutableArray *a2 = [[NSMutableArray alloc] init];  [a2 addObjectsFromArray:[list componentsSeparatedByString:@", "]];    NSLog(@"array is  %@",a2);  NSLog(@"array o  %@",[a2 objectAtIndex:0]);

Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »