我在获取时会破坏托管对象的所有属性以获得性能优势,因为我将全部使用它们并且结果集很小。但是,在获取期间,关系是否也会出现故障?
答案 0 :(得分:1)
看the documentation它只提到预取的属性,而不是关系。我打赌人际关系仍然存在问题。
但是,您可以轻松找到自己 - 只需查看日志中的对象:)
例如,如果您有公司有很多员工并且您要求公司,那么在您调试时(假设您没有覆盖描述方法)
NSLog(@"%@", company);
您将获得之类的内容
<Company 0x123456
name : "Company Name"
employees : <NSSet data:fault>
>
如果没有出现故障,您会看到员工列表而不是 fault 这个词:)
答案 1 :(得分:0)
我意识到这个问题已经过时了,但看起来Apple已经添加了一个选项来设置哪些关系应该被预取而不是出现故障:
这是从NSFetchRequest.h获取的片段
/* Returns/sets an array of relationship keypaths to prefetch along with the entity for the request. The array contains keypath strings in NSKeyValueCoding notation, as you would normally use with valueForKeyPath. (Prefetching allows Core Data to obtain developer-specified related objects in a single fetch (per entity), rather than incurring subsequent access to the store for each individual record as their faults are tripped.) Defaults to an empty array (no prefetching.)
*/
- (NSArray *)relationshipKeyPathsForPrefetching NS_AVAILABLE(10_5,3_0);
- (void)setRelationshipKeyPathsForPrefetching:(NSArray *)keys NS_AVAILABLE(10_5,3_0);