In Xcode, I store some NSString
in NSMutableArray
.
Hello
Here
MyBook
Bible
Array
Name2
There
IamCriminal
User can enter string.
Name2
I need to delete that particular string from NSMutableArray
without knowing index of the string. I have some idea that, Use iteration. Any other Best way. Plz Give with sample codings.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With