将NSPredicate与Core Data NSFetchedResultsController配合使用

编程入门 行业动态 更新时间:2024-10-25 10:28:08
本文介绍了将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配合使用

本文发布于:2023-11-01 18:40:35,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1550099.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:Core   NSPredicate   NSFetchedResultsController   Data

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!