I'm trying to store different data types in a NSDictionary to save in NSUserdefaults when the game terminates. I'm trying to store a char, 3 floats and a string, I keep getting a warning on the char and the floats and I cant seem to find the answer anywhere. 1)Do i even need to setup the arrays? 2) How do I store the different data types to an object like an array or dictionary? the code looks like the this:
gameKeys = [[NSArray alloc] initWithObjects:@"gameScore",@"gameSound",@"gameDifficulty",@"theGameLoopSpeed",@"theDelayGameSpeed",nil];
gameValues = [[NSMutableArray alloc] init];
[gameValues setValue:score forKey:@"gameScore"];
[gameValues addObject:[NSString stringWithFormat:score]];// unsigned char
[gameValues addObject:[NSString stringWithFormat:sound]];//string
[gameValues addObject:[NSString stringWithFormat:gameDifficulty]];// char
[gameValues addObject:[NSNumber numberWithFloat:gameLoopSpeed]];// float
[gameValues addObject:[NSNumber numberWithFloat:delayGameLoopSpeed]];//float
NSDictionary *gameDict = [[NSDictionary alloc] initWithObjects:gameKeys forKeys:gameValues];
[gameDict setObject:[NSString stringWithFormat:score] forKey:@"gameScore"];//unsigned char
[gameDict setObject:[NSString stringWithFormat:sound] forKey:@"gameSound"];//string
[gameDict setObject:[NSString stringWithFormat:gameDifficulty] forKey:@"theGameDifficulty"];//char
[gameDict setObject:[NSNumber numberWithFloat:gameLoopSpeed] forKey:@"theGameLoopSpeed"];//float
[gameDict setObject:[NSNumber numberWithFloat:delayGameLoopSpeed] forKey:@"theDelayGameLoopSpeed"];//float
NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
userDefaults = gameDict;
[userDefaults synchronize];