Search NSArray for value matching value

后端 未结 8 1167
一生所求
一生所求 2020-11-30 07:52

I have an NSArray of objects, which has a particular property called name (type NSString).
I have a second NSArray of NSStrings which are

8条回答
  •  既然无缘
    2020-11-30 08:02

    I like to use this method:

    NSIndexSet *indexes = [_items indexesOfObjectsPassingTest:^BOOL(id obj, NSUInteger idx, BOOL *stop) {
       return ((MyObject *)obj).name isEqualToString:name];
    }];
    
    if (indexes.count != 0) {
    //extract your objects from the indexSet, and do what you like...
    }
    

提交回复
热议问题