核心数据NSPredicate按实体类过滤? [英] Core Data NSPredicate filter by entity class?

查看:203
本文介绍了核心数据NSPredicate按实体类过滤?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何创建 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 class Contact?

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 of Person (abstract entity). Person has many identities, which can be emails, phones, or usernames.

To create a text-message-like typeahead, I want to create an NSFetchRequest for Identity entities where person is of class Contact.

解决方案

You are perhaps mixing up a few things. The answer you indicate is about a predicate to filter anrray of UIViews. 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屋!

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