check and remove a particular string from nsmutable array without index
you can use containsObject
method in an NSMutableArray
if ([yourArray containsObject:@"object"]) {
[yourArray removeObject:@"object"];
}
Swift:
if yourArray.contains("object") {
yourArray = yourArray.filter{ $0 != "object" }
}
[array removeObject:@"Name2"];
The documentation for NSMutableArray’s removeObject: method states:
matches are determined on the basis of an object’s response to the isEqual: message
In other words, this method iterates over your array comparing the objects to @"Name2"
. If an object is equal to @"Name2"
, it is removed from the array.