I am making a high score manager.
I load and save as follows:
-(void)load
{
NSMutableArray* scores = [NSMutableArray arrayWithArray:[[NSUserDefaults standardUserDefaults] objectForKey:HIGH_SCORE_KEY]];
if(scores == nil)
{
highscores = [NSMutableArray array];
}
else
{
highscores = scores;
}
}
-(void)save
{
[[NSUserDefaults standardUserDefaults] setObject:highscores forKey:HIGH_SCORE_KEY];
}
I am storing HighScore objects:
#import <Foundation/Foundation.h>
@interface HighScore : NSObject
{
int score;
NSString* name;
}
-(int)score;
-(NSString*)name;
-(id)init;
-(id)initWithName:(NSString*)playerName andScore:(int)playerScore;
-(BOOL)isEqual:(id)object;
-(BOOL)isLessThan:(id)object;
@end
There is nothing particularly complex about this class. However, when I load, the load does not return nil but returns an empty array, indicating to me that serializing probably failed for some reason.
Any ideas?
Thanks