2012-03-24 7 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をご覧ください。

関連する問題