objective-c – 核心数据:提取请求中的抽象实体

objective-c – 核心数据:提取请求中的抽象实体,第1张

概述假设我有一个核心数据模型与一个抽象实体,称为“动物”。然后,我有很多其他实体继承这个抽象实体:“狮子”,“狗”,“猫”等(我不是在开发一个动物园程序,但这个比喻对我解释的问题很好!) 我想知道的是:我可以通过这样做一次“所有动物”: NSFetchRequest *searchRequest = [[NSFetchRequest alloc] init];[searchRequest setEn 假设我有一个核心数据模型与一个抽象实体,称为“动物”。然后,我有很多其他实体继承这个抽象实体:“狮子”,“狗”,“猫”等(我不是在开发一个动物园程序,但这个比喻对我解释的问题很好!)

我想知道的是:我可以通过这样做一次“所有动物”:

NSFetchRequest *searchRequest = [[NSFetchRequest alloc] init];[searchRequest setEntity:[NSEntityDescription entityForname:@"Animal" inManagedobjectContext:aContext]];NSArray *matchedobjects = [aContext executeFetchRequest:searchRequest error:nil];

我理解有NSEntityDescription的方法来确定一个实体是否继承自另一个。但是有没有一种快速的方式来抓取所有实体的特定(抽象)类型—在这种情况下,“动物”?

如果上面的方法是无效的,什么是最有效的方式去做这个?谢谢!

解决方法 你肯定可以使用这种方法。

从苹果的Core Data Programming guide(滚动到文章的底部):

If you define an entity inheritance hIErarchy (see “Entity inheritance”),when you specify a super-entity as the entity for a fetch request,the request returns all matching instances of the super-entity and of sub-entitIEs. In some applications,you might specify a super-entity as being abstract (see “Abstract EntitIEs”). To fetch matching instances of all concrete sub-entitIEs of the abstract entity,you set the entity for fetch specification to be the abstract entity. In the case of the domain described in “Abstract EntitIEs,” if you specify a fetch request with the Graphic entity,the fetch returns matching instances of Circle,TextArea,and line.

总结

以上是内存溢出为你收集整理的objective-c – 核心数据:提取请求中的抽象实体全部内容,希望文章能够帮你解决objective-c – 核心数据:提取请求中的抽象实体所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/1044282.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-24
下一篇 2022-05-24

发表评论

登录后才能评论

评论列表(0条)

保存