2012-04-04 6 views
-1

私は2つの配列を持っていますNSArrayのオブジェクトを別のNSMutableArrayから削除するにはどうすればいいですか?

私はもう一方から削除したいです。

removeObjectは使用できません:ポインタが異なるためです。

私は、他の配列からそのプロパティに基づいてオブジェクトを削除するにはどうすればよい

(X.A == y.a)そのプロパティに基づいてオブジェクトを削除していますか?

おかげで、

+0

を試してみてくださいあなたが望むことをやっている。 – Vignesh

+0

編集した質問 – nurxyz

+0

サンプルを気遣う? – Vignesh

答えて

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

この例を試してみてくださいシングルループのためのもう一つのアイデアは、サブクラス化するか、独自のカテゴリを作るのいずれか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); 
関連する問題