Fast way to search the properties of objects in an NSArray

后端 未结 2 1028
滥情空心
滥情空心 2021-01-27 02:52

I have an NSArray of custom objects that all have a @property name of type NSString. How can I quickly enumerate through the array and cre

相关标签:
2条回答
  • 2021-01-27 02:56

    Please have a look at NSPredicates ! They are highly efficient when you are searching / filtering through array results. This is the documentation!

    0 讨论(0)
  • 2021-01-27 03:04
    NSString *searchString = @"dog";
    NSPredicate *predicate = [NSPredicate predicateWithFormat:@"SELF.name contains %@", searchString];
    NSArray *filteredArray = [testArray filteredArrayUsingPredicate:predicate];
    
    0 讨论(0)
提交回复
热议问题