2

I'm developing for iOS 5, say I have 2 arrays, the second only contains items contained on the first one.

I want to remove this object in every array it's present.

So, is there a way to easily remove an object from all arrays that contains it?

1 Answer 1

2
NSMutableArray *totalArray = [ [ NSMutableArray alloc] init];

    //here i assume u want to delete NSString object vijay in all arrays

NSString *toDelete=@"vijay";

[totalArray addObject:firstArray];

[totalArray addObject:secondArray];

for (NSMutableArray *arr in totalArray) {



    if ([arr containsObject:toDelete]) {

        [arr removeObject:toDelete];

    }



}

NSLog(@"firstarry : %@ \n\n",firstArray);

NSLog(@"secondarray : %@ \n\n",secondArray);
2
  • Hi, I want to remove only this specific item from all the arrays, not all the items of one array
    – Lucas
    Aug 24, 2011 at 13:20
  • I'm talking about iOS 4, where there's no ARC
    – Lucas
    Aug 25, 2011 at 8:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.