Core data 序列化NSManagedObject
我在NSManagedObject上使用一个名为NSManagedObject+Serialization.h的类别,位于此处 一切都很好,但我需要实现这一点,但不知道如何实现?我想跳过一些对象Core data 序列化NSManagedObject,core-data,nsmanagedobject,Core Data,Nsmanagedobject,我在NSManagedObject上使用一个名为NSManagedObject+Serialization.h的类别,位于此处 一切都很好,但我需要实现这一点,但不知道如何实现?我想跳过一些对象 - (NSDictionary*) toDictionary { // Check to see there are any objects that should be skipped in the traversal. // This method can be optionally impleme
- (NSDictionary*) toDictionary {
// Check to see there are any objects that should be skipped in the traversal.
// This method can be optionally implemented by NSManagedObject subclasses.
NSMutableSet *traversedObjects = nil;
if ([self respondsToSelector:@selector(serializationObjectsToSkip)]) {
traversedObjects = [self performSelector:@selector(serializationObjectsToSkip)];
}
return [self toDictionaryWithTraversalHistory:traversedObjects];
}
如何添加要跳过的对象关系
非常感谢在托管对象子类中,您必须实现
序列化对象跳过
:- (NSMutableSet*) serializationObjectsToSkip
{
NSMutableSet* objectsToSkip = [NSMutableSet new];
//Here you select objects that relate to this object and you don't want to serialise.
//Insert them into `objectsToSkip`
return objectsToSkip;
}
然而,序列化的实现看起来有问题(第80行和第93行)。。。(如果没有提前提供要跳过的所有对象)跳过
relatedObject
的toDictionary
,因此相关对象可能要跳过的对象将不会添加到遍历历史集…一个快速修复方法可能是用
toDictionary
的完整实现替换这些行,并合并遍历历史集和返回的objectsToSkip
集…更好的解决方案是将
toDictionary
方法的签名更改为接受遍历历史,并在那里进行集合合并,并将上述行替换为相关对象的toDictionary
。