我试过了:
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子类保存到文件中?
答案 0 :(得分:3)
如果您希望encodeWithCoder:
工作,则需要在JEntry
课程中实施 NSArchiver
。您可能也需要initWithCoder:
,以便以后可以反序列化。