Reputation: 735
I have an NSMutableArray of NSArray's inside it. This is my current structure:
Paused index (
(
0,
3579
),
(
1,
3538
)
)
how to search through the array and remove the object 3538? My expected result is:
Paused index (
(
0,
3579
)
)
How can I get the index of the outer array? I can already do the search but how can I remove the object in that index?
Upvotes: 1
Views: 2697
Reputation: 506
As you have this array
Array_Paused_index (
(
0,
3579
),
(
1,
3538
)
)
Take one more Array
Array = [Array_Paused_index objectAtIndex: 0];
Result will be
Array
(
(
0,
3579
)
)
OR SECOND METHOD :
[Array_Paused_index removeObjectAtIndex:1];
Upvotes: 0
Reputation: 10251
This is a very straight forward way.
NSArray *firstArray = [NSArray arrayWithObjects:[NSNumber numberWithInt:100],[NSNumber numberWithInt:1000], nil];
NSArray *secondArray = [NSArray arrayWithObjects:[NSNumber numberWithInt:100],[NSNumber numberWithInt:5000], nil];
NSMutableArray *arrayWithArray = [NSMutableArray arrayWithObjects:firstArray,secondArray,nil];
int i = 0;
for (NSArray *innerArray in arrayWithArray)
{
if ([innerArray containsObject:[NSNumber numberWithInt:5000]])
{
break;
}
i++;
}
NSLog(@"Index of object %d",i);
[arrayWithArray removeObjectAtIndex:i];
Some other intelligent way should be there.
EDIT: I think this is little better.
int i = [arrayWithArray indexOfObjectPassingTest:^BOOL(id element,NSUInteger idx,BOOL *stop)
{
return [(NSArray *)element containsObject:[NSNumber numberWithInt:5000]];
}];
NSLog(@"Index of object %d",i);
if (i >= 0 && i < [arrayWithArray count])
{
[arrayWithArray removeObjectAtIndex:i];
}
Upvotes: 1