我有一个用户对象的 NSMutableArray,即 NSManagedObjects。用户对象不具有另一个对象中的一些传记信息,即通过一对一关系连接到 User 的 Bio 。是否可以根据关系抓取对象数组?
以下行效果很好,创建了用户的用户名数组(uname 是用户的属性):
NSMutableArray * userNames = [[_users valueForKey:@"uname"] mutableCopy];
但是,该行可以编译,但在运行时会出现错误...
NSMutableArray * firsts =[[_users valueForKey:@"bio.firstName"] mutableCopy];
//where bio is the name of the relationship to the Bio entity and firstName is the first name of the user.
它给出的错误是:
[NSNull length]:
无法识别的选择器发送到实例 0x3ab0ca70
最佳答案
是的,但您需要使用 -valueForKeyPath:
而不是 -valueForKey:
来告诉框架您将要遍历关系。
关于iOS/核心数据 : Can value for key access relationships?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36944386/