2012-04-04 257 views
-1

我有2個陣列,如何從另一個NSMutableArray中移除一個NSArray的對象?

我想從另一箇中刪除一個。

我不能使用removeObject:因爲指針是不同的。

我根據自己的屬性刪除對象(x.a == y.a)

如何刪除根據其性質從其他數組對象?

感謝,

+0

什麼是你的問題?你正在做你想做的事。 – Vignesh 2012-04-04 12:41:22

+0

編輯我的問題 – nurxyz 2012-04-04 12:45:54

+0

小心給樣品? – Vignesh 2012-04-04 12:51:01

回答

0

嘗試這個例子

for(int i = 0; i< firstArray.count ; i++){ 
    NSString *first = [firstArray objectAtIndex:i]; 
    for(int j = 0; j< secondArray.count; j++){ 
     NSString *second = [econdArray objectAtIndex:j]; 
     if([first isEqualToString:second]){ 

     /// Do your methods 

     } 
    } 
} 
0

單for循環就足夠了,另一個想法是可以通過繼承或使自己的類別覆蓋的removeObject方法。

0
BOOL GotOne = NO; 

for(int i =0; i < mutableArray.count; i++) 
{ 
    NSArray *temp = [mutableArray objectAtIndex:i]; 

    for(int j = 0; j < temp.count; j++) 
    { 
     //Do what u want with temp or check any condition 
     if(success) 
     { 
      GotOne = YES; 
      break; 
     } 
    } 
    if(GotOne) 
     { 
      [mutableArray removeObjectAtIndex:i]; 
      GotOne = NO; 
     } 
} 
4

試試這個

NSMutableArray *arrFirst = [NSMutableArray arrayWithObjects:[NSDictionary dictionaryWithObjectsAndKeys:@"1",@"topic_id",@"abc",@"topic_name",nil], 
        [NSDictionary dictionaryWithObjectsAndKeys:@"2",@"topic_id",@"opq",@"topic_name",nil], 
        [NSDictionary dictionaryWithObjectsAndKeys:@"3",@"topic_id",@"xyz",@"topic_name",nil], nil]; 

NSArray *arrSec = [NSArray arrayWithObject:[NSDictionary dictionaryWithObjectsAndKeys:@"2",@"topic_id",@"opq",@"topic_name",nil]]; 

NSArray *temp = [arrFirst filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"SELF IN %@",arrSec]]; 
[arrFirst removeObjectsInArray:temp]; 
NSLog(@"%@",arrFirst); 
相關問題