将NSPredicate与Core Data NSFetchedResultsController配合使用 [英] Using NSPredicate with Core Data NSFetchedResultsController

查看:208
本文介绍了将NSPredicate与Core Data NSFetchedResultsController配合使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个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配合使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆