I have an object from a NSObject class that I call “brand” and has the following properties:
.name
.number
.site
at a given time, dozens of these objects are stored on a NSMutableArray, something like:
object 1
object 2
object 3
object 4
...
I would like to be able to retrieve a given object from the array by its number. Not the index of the object on the array but the number property of the object (get object
that has the number property equal to 10, for example).
I know that NSArrays have smart methods for retrieving stuff but I don’t know them deeply cause I use this rarely. Is there any way to retrieve that object from the array without having to iterate thru all objects on the array and check each object’s number property?
Can you guys help? thanks.
I would recommend
NSPredicate. You could do it with something like this, assuminglistOfItemsis your array containing yourNSObject‘s with said properties.Your filtered results, any numbers matching
10will now be in thefilteredarray. If you want to cast back to your object, you can do something like this:Hope this helps.