Morten Gustafsson Morten Gustafsson - 2 months ago 5x
iOS Question

iOS - Make a copy of a array object into another

I have a little problem, and I need help.

I want to loop through a multidimensional array, and every time I find a value for a key ex."name" that is equal to ex. "Hello". I want to copy that array object into another array.

How do I do that?


I assume you have a 2-dimensional array and since I don't know how your objects within the array look like I take the id type and the method valueForKey:

 NSMutableArray *tmp = [[NSMutableArray alloc] init];
 for(NSArray *dim1Array in yourMultidimensionalArray)
    for(id obj in dim1Array)
       if([[obj valueForKey:@"name"] isEqualToString:@"Hello"])
          [tmp addObject:dim1Array];
          break; // I assume you only want to add it once