我有一个fetchedResultsController,返回了我的实体帐户的所有记录。
我想快速搜索所有帐户记录的属性lastName= = value,并给我返回Account对象,或至少在fetchedResultsController中的对象的indexPath。
除了遍历每个objectAtIndexPath之外,是否有更好的方法使用NSPredicate搜索fetchController?
mootymoots,只是用另一个谓词过滤抓取的对象...
NSPredicate * lastNameMatch = ... NSArray * matchingFetchedObjects = [fetchedResultsController.fetchedObjects filteredArrayUsingPredicate:lastNameMatch];这会使您的 fetchedResultsController 结果,但是给你一个数组,其中包含了最后一个名字谓词的匹配。
I have a fetchedResultsController that has returned all records for my entity "Account".
I would like to quickly search all Account records for the attribute "lastName" == value, and give me back the Account object, or at least the indexPath of the object in the fetchedResultsController. There should only be 1 object returned.
Other than iterate through every objectAtIndexPath, is there a better way to search the fetchController using NSPredicate?
解决方案mootymoots, just filter the fetched objects with another predicate...
NSPredicate *lastNameMatch = ... NSArray *matchingFetchedObjects = [fetchedResultsController.fetchedObjects filteredArrayUsingPredicate:lastNameMatch];That leaves your fetchedResultsController results un-altered, but gives you an array with a match for the last name predicate.
更多推荐
将NSPredicate与Core Data NSFetchedResultsController配合使用
发布评论