简体   繁体   English

访问关系对象(CoreData)

[英]Accessing Relationship Objects (CoreData)

In my core data model I have two entities, let's call them A and B, A holds multiple B objects ( A<-->>B ). 在我的核心数据模型中,我有两个实体,我们称它们为A和B,A拥有多个B对象( A<-->>B )。 allBObjects is the To-Many Relationship that holds the B objects. allBObjects是保存B对象的To-Many关系。

As this code 作为这个代码

[[AObject valueForKey:@"allBObjects"] count];

works, I thought that this should work too: 工作,我认为这也应该工作:

[[AObject valueForKey:@"allBObjects"] objectAtIndex:index];

However it doesn't, as the relationship objects do not seem to be stored as arrays. 但是事实并非如此,因为关系对象似乎没有存储为数组。 Does anybody know how to access objects in allBObjects of AObject ? 有人知道如何访问allBObjectsAObject对象吗?

I would appreciate some help, Fabian Fabian,我很感激一些帮助

from Cocoa Dev Central: Core Data Class Overview : 来自Cocoa Dev Central:核心数据类概述

Managed Objects have no actual order in the Context or in Relationships. 托管对象在上下文或关系中没有实际顺序。 In fact, the "native" collection class for Core Data is NSSet. 实际上,Core Data的“本机”集合类是NSSet。 You can order the results of Fetch Request using NSSortDescriptors, but the sorting is not saved to the data store. 您可以使用NSSortDescriptors订购获取请求的结果,但排序不会保存到数据存储中。

Try 尝试

 [[[[AObject valueForKey:@"allBObjects"] objectAtIndex:index] allObjects] objectAtIndex:index];

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM