2014-03-03 2 views
0

https://gist.github.com/nuthatch/5607405에있는 NSManagedObject + Serialization.h라는 NSManagedObject에서 범주를 사용하고 있습니다.NSManagedObject 직렬화

모든 것이 잘 작동하지만이 방법을 구현해야하나요? 나는 어떤 물건을 건너 뛰고 싶다.

- (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]; 

} 내가 개체의 관계를 추가 할 수는 생략하는 방법

?

많은 감사

관리되는 객체의 하위 클래스에서

답변

0

당신이 serializationObjectsToSkip 구현해야하지만

- (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) (보이는 당신이 경우

relatedObjecttoDictionary은 건너 뛰므로 관련 개체가 건너 뛰기를 원하는 개체가있을 수 있습니다. LL ...

빠른 수정이 전체 toDictionary의 구현 및 순회 역사 세트와 반환 objectsToSkip 세트를 병합과 함께이 라인을 대체 할 수 있습니다 ... 순회 내역 세트에 추가 할 수 없습니다

더 좋은 해결책은 트래버스 이력을 받아들이 기 위해 toDictionary 메서드의 서명을 변경하고 거기에서 병합을 설정하고 위의 행을 관련 객체의 toDictionary으로 바꾸는 것입니다.

+0

감사합니다. 완벽하게 작동합니다! – ourmanflint