user379468 user379468 - 1 year ago 70
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.

Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download