获取与核心数据的关系
我有两个具有双向关系的托管对象。 它是一个包含“segment”对象的“segmentWithDetails”。
我用来
NSEntityDescription *entity = [NSEntityDescription entityForName:@"SegmentWithDetails"
inManagedObjectContext:connectionDetailsService.connectionDetailsContext];
[fetchRequest setEntity:entity];
获取我的细分详细信息。这工作正常。
但是,当我尝试检索包含的段时,我得到了零。
我试图用
Segment *segment = [segmentWithDetails valueForKeyPath:@"segment"];
和 with 来
Segment *segment = segmentWithDetails.segment;
获取它但这不起作用(=nil)。我还尝试修改 NSFetchedResultsController。 我添加了以下内容:
[fetchRequest setRelationshipKeyPathsForPrefetching:[NSArray arrayWithObject:@"segment"]];
[fetchRequest setIncludesSubentities:YES];
但这两者似乎没有任何区别。 根据我对苹果精美文档的理解,这种关系应该只在使用错误的情况下起作用。
我在这里缺少什么? 如何从“segmentWithDetails”获取关系对象“segment”?
I have two managed objects which have a bidirectional relationship.
It is a 'segmentWithDetails' which contains a 'segment' object.
I use
NSEntityDescription *entity = [NSEntityDescription entityForName:@"SegmentWithDetails"
inManagedObjectContext:connectionDetailsService.connectionDetailsContext];
[fetchRequest setEntity:entity];
to get my segmentWith Details. This works ok.
BUT, when I try to retrieve the contained segment, I get nil.
I've tried to get it with
Segment *segment = [segmentWithDetails valueForKeyPath:@"segment"];
and with
Segment *segment = segmentWithDetails.segment;
But this does not work (=nil). I've also tried modifying the NSFetchedResultsController.
I added the following:
[fetchRequest setRelationshipKeyPathsForPrefetching:[NSArray arrayWithObject:@"segment"]];
[fetchRequest setIncludesSubentities:YES];
But both of these do not seem to make any difference.
From what I understand out of Apple fine documentation, the relationship should just work using faults.
What am I missing here?
How do I get to the relationship object 'segment' from 'segmentWithDetails' ??
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
它应该像你描述的那样工作。您确定“段”对象/关系确实存在并且包含真实对象吗?检查数据模型是否该关系不是可选的,并检查您的代码是否实际存储了某些内容。
It should just work like you describe. Are you sure the "segment" object/relation actually exists and contains a real object? Check the data model that this relation isn't optional and check your code that you have actually stored something.
问题解决了。
这不是我如何读取数据,而是我如何将其放入 CoreData。
上面发布的代码确实是正确的。感谢 Jaanus 的回复。
Problem solved.
It was not how I read the data, but how I put it in CoreData.
The posted code above is indeed correct. Thanx for the response Jaanus.