2012-03-24 3 views
-4

내가 시도 :커스텀 NSObject 클래스를 파일에 저장하려면 어떻게해야합니까?

NSData *data = [NSKeyedArchiver archivedDataWithRootObject:dictionary]; 

    BOOL success = [data writeToFile:entryPath atomically:YES]; 

그러나 어떤 이유로,이 오류와 함께 추락 :

2012-03-24 20:06:13.550 Journal[1348:707] -[JEntry encodeWithCoder:]: unrecognized selector sent to instance 0x25d1a0 
2012-03-24 20:06:13.553 Journal[1348:707] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[JEntry encodeWithCoder:]: unrecognized selector sent to instance 0x25d1a0' 

어떻게 다른 내가 파일에 NSObject의 서브 클래스를 저장합니까?

답변

3

당신은 당신이 일을 NSArchiver를 원하는 경우 JEntry 클래스encodeWithCoder:을 구현 해야합니다. 나중에 비 직렬화 할 수 있도록 initWithCoder:도 필요합니다.

시작하려면 Archives and Serializations Programming Guide을 읽으십시오.

관련 문제