I am trying to save some custom classes / data to a file in an iPhone / iPad application.
I have an RSHighscoreList class
@interface RSHighscoreList : NSObject { NSMutableArray *list; }
which contains the RSHighscore objects in the list
@interface RSHighscore : NSObject { NSString *playerName; NSInteger points; }
When I try to save everything to a file
- (void)writeDataStore { RSDataStore *tmpStore = [[RSDataStore alloc] init]; _tmpStore.highscorelist = self.highscorelist.list; NSMutableData *data = [[NSMutableData alloc] init]; NSKeyedArchiver *archiver = [[NSKeyedArchiver alloc] initForWritingWithMutableData:data]; [archiver encodeObject:tmpStore forKey:kDataKey]; [archiver finishEncoding]; [data writeToFile:[self dataFilePath] atomically:YES]; [archiver release]; [data release]; } @interface RSDataStore : NSObject <NSCoding, NSCopying> { NSMutableArray *highscorelist; } - (void)encodeWithCoder:(NSCoder *)encoder { [encoder encodeObject:highscorelist forKey:@"Highscorelist"]; }
Application crashes with error message
- [RSHighscore encodeWithCoder:]: unrecognized selector sent to instance 0x573cc20
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '- [RSHighscore encodeWithCoder:]: unrecognized selector sent to instance 0x573cc20'
I wonder why the error speaks of RSHighscore, even if it is "wrapped". Anyone have a good idea?
source share