Saturday, June 1, 2013

NSMutableArray removeObjectIdenticalTo example in Objective C (iOS).


NSMutableArray removeObjectIdenticalTo

Removes all occurrences of a given object in the array.

- (void)removeObjectIdenticalTo:(id)anObject

Parameters
anObject
The object to remove from the array.

Discussion of [NSMutableArray removeObjectIdenticalTo]
This method uses the indexOfObjectIdenticalTo: method to locate matches and then removes them by using removeObjectAtIndex:. Thus, matches are determined using object addresses. If the array does not contain anObject, the method has no effect (although it does incur the overhead of searching the contents).

NSMutableArray removeObjectIdenticalTo example.
NSNull *nullValue = [NSNull null];

[mutArrSkills removeObjectIdenticalTo:nullValue];

Example of [NSMutableArray removeObjectIdenticalTo].
if ([favs containsObject:parent])  //check for present of parent in the favs
{
    [favs removeObjectIdenticalTo:parent];  //remove all occurrences of parent
} else
    [favs addObject:parent];

NSMutableArray removeObjectIdenticalTo example.
NSMutableArray *allViewControllers = [NSMutableArray arrayWithArray: navigationController.viewControllers];
[allViewControllers removeObjectIdenticalTo: removedViewController];
navigationController.viewControllers = allViewControllers;

End of NSMutableArray removeObjectIdenticalTo example article.