开发者

Accessing Relationship Objects (CoreData)

开发者 https://www.devze.com 2023-01-26 13:47 出处:网络
In my core data model I have two entities, let\'s call them A and B, A holds multiple B objects (A<-->>B). allBObjects is the To-Many Relationship that holds the B objects开发者_高级运维.

In my core data model I have two entities, let's call them A and B, A holds multiple B objects (A<-->>B). allBObjects is the To-Many Relationship that holds the B objects开发者_高级运维.

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?

I would appreciate some help, Fabian


from Cocoa Dev Central: Core Data Class Overview:

Managed Objects have no actual order in the Context or in Relationships. In fact, the "native" collection class for Core Data is NSSet. You can order the results of Fetch Request using NSSortDescriptors, but the sorting is not saved to the data store.

Try

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

精彩评论

暂无评论...
验证码 换一张
取 消