核心数据NSPredicate按实体类过滤? [英] Core Data NSPredicate filter by entity class?
问题描述
如何创建 NSPredicate
以按类联系人
?实体过滤?
对 NSPredicate检查类对象类的解决方案崩溃:
[NSPredicate predicateWithFormat:@person.class ==%@,[Contact class]];
***由于未捕获异常而终止应用程序'NSInvalidArgumentException',
原因:'keypath person.class在实体中找不到< NSSQLEntity User id = 12>'
背景
我有Core Data实体
User
(app user)&联系
(地址簿联系人),Person
(抽象实体)的孩子。人有许多
身份,可以是
或电子邮件
code>电话用户名
。
我想为
。Identity
创建NSFetchRequest
实体,其中person
是
类别 c
解决方案也许混合了几件事情。你指出的答案是关于一个谓词,以筛选
UIView
的anrray。
要实现所需的结果,只需设置
实体
您的撷取要求至@联络人
。How would I create an
NSPredicate
to filter by entity of classContact
?The solution to NSPredicate check for kind of object class crashes:
[NSPredicate predicateWithFormat:@"person.class == %@", [Contact class]]; *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'keypath person.class not found in entity <NSSQLEntity User id=12>'
Background
I have the Core Data entities
User
(app user) &Contact
(address book contact), both children ofPerson
(abstract entity).Person
has manyidentities
, which can beemails
,phones
, orusernames
.To create a text-message-like typeahead, I want to create an
NSFetchRequest
forIdentity
entities whereperson
is of classContact
.解决方案You are perhaps mixing up a few things. The answer you indicate is about a predicate to filter anrray of
UIView
s. A predicate in core data works in a slightly different way.To achieve your desired result, simply set the
entity
of your fetch request to@"Contact"
.这篇关于核心数据NSPredicate按实体类过滤?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!