开发者

KVC select by criteria

开发者 https://www.devze.com 2022-12-13 04:25 出处:网络
I have a array of objects that select开发者_开发百科ed from core data. I need select from this set subset of object that correspond to condition.

I have a array of objects that select开发者_开发百科ed from core data. I need select from this set subset of object that correspond to condition. How to do it?


If I read you correctly you want to filter your array based on a condition met by some of the objects in it?

You can do this by using NSPredicate and call filteredArrayWithPredicate: on your array.

NSPredicate *predicate = [NSPredicate predicateWithFormat:@"attribute == YES"];
NSArray *filteredArray = [originalArray filteredArrayWithPredicate:predicate];

You can read more about using predicates in the Predicates Programming Guide

You can also use predicates to filter your NSFetchRequest directly when retrieving the data from Core Data.

0

精彩评论

暂无评论...
验证码 换一张
取 消