[英]remove object from NSMutableArray that contains NSArray
I have an NSMutableArray of NSArray's inside it. 我里面有一个NSArray的NSMutableArray。 This is my current structure: 这是我当前的结构:
Paused index (
(
0,
3579
),
(
1,
3538
)
)
how to search through the array and remove the object 3538? 如何搜索数组并删除对象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? 我已经可以进行搜索了,但是如何删除该索引中的对象呢?
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];
}
As you have this array 当你有这个数组
Array_Paused_index ( Array_Paused_index(
(
0,
3579
),
(
1,
3538
)
) )
Take one more Array 再取一个数组
Array = [Array_Paused_index objectAtIndex: 0]; Array = [Array_Paused_index objectAtIndex:0];
Result will be 结果将是
Array 数组
( (
(
0,
3579
)
) )
OR SECOND METHOD : 或第二种方法:
[Array_Paused_index removeObjectAtIndex:1]; [Array_Paused_index removeObjectAtIndex:1];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.