view raw
user379468 user379468 - 7 months ago 32
Objective-C Question

how do I search an array of objects and return only those objects with certain uids in objective c

I have an array of uids, and another array of objects. The objects structure is such that it has a name and a uid. I would like to search the array or objects, and return an array of those objects that match the uids from the first array. I was exploring using undersore.m but I'm not sure if this is appropriate.


Use a simple loop:

NSArray *uids = ... // your array of UIDs
NSArray *objects = ... // your array of objects with a name and uid
NSMutableArray *matches = [NSMutableArray array];
for (SomeClass *object in objects) {
    if ([uids containsObject:object.uid]) {
        [matches addObject:object];

matches will contain the matching objects.

Obviously you need to change SomeClass to your actual class that has the name and uid. And I'm assuming your class has a uid property. Adjust as needed.