我似乎无法在我的 ios 用户默认值中重新编辑此对象。这是我的代码...
NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
[userDefaults setObject:nil forKey:@"savedScoreCards2"];
在我这样做之前,我将键 savedScoreCards 设置为一个巨大的 3-d 字典,现在当我尝试重写它甚至将键设置为 nil 时,我不久前设置的那个巨大的 3-d 字典仍然存在。我似乎无法过度写入/替换它(零)或另一个巨大的 3-d 字典。有任何想法吗?
更新:
+ (void)saveCurrentScoreCard
{
//save score card
NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
NSMutableDictionary *savedScoreCards = [[NSMutableDictionary alloc] init];
[userDefaults setObject:nil forKey:@"savedScoreCards2"];//reset at beginning
NSMutableArray *golferOneScoresu = [userDefaults arrayForKey:@"golferOneScoresArray"];
NSMutableArray *golferTwoScoresu = [userDefaults arrayForKey:@"golferTwoScoresArray"];
NSMutableDictionary *golferIconsu = [userDefaults objectForKey:@"golferIconsFirstScene"];
NSMutableArray *golferThreeScoresu = [userDefaults arrayForKey:@"golferThreeScoresArray"];
NSMutableArray *golferFourScoresu = [userDefaults arrayForKey:@"golferFourScoresArray"];
NSMutableDictionary *golferIcons2u = [userDefaults objectForKey:@"golferIcons"];
NSMutableArray *golferNamesu = [userDefaults objectForKey:@"golferNames"];
NSMutableArray *golferNames = [[NSMutableArray alloc] initWithArray:golferNamesu copyItems:YES];
NSMutableDictionary *golferIconsSceneOne = [[NSMutableDictionary alloc]initWithDictionary:golferIconsu];
NSMutableDictionary *golferIcons = [[NSMutableDictionary alloc]initWithDictionary:golferIcons2u];
NSMutableArray *golferFourScores = [[NSMutableArray alloc] initWithArray:golferFourScoresu copyItems:YES];
NSMutableArray *golferThreeScores = [[NSMutableArray alloc] initWithArray:golferThreeScoresu copyItems:YES];
NSMutableArray *golferOneScores = [[NSMutableArray alloc] initWithArray:golferOneScoresu copyItems:YES];
NSMutableArray *golferTwoScores = [[NSMutableArray alloc] initWithArray:golferTwoScoresu copyItems:YES];
NSMutableDictionary *currentScoreCard = [[NSMutableDictionary alloc] init];
[currentScoreCard setObject:golferNames forKey:@"golferNames"];
[currentScoreCard setObject:golferIconsSceneOne forKey:@"golferIconsFirstScene"];
[currentScoreCard setObject:golferIcons forKey:@"golferIcons"];
[currentScoreCard setObject:golferOneScores forKey:@"golferOneScoresArray"];
[currentScoreCard setObject:golferTwoScores forKey:@"golferTwoScoresArray"];
[currentScoreCard setObject:golferThreeScores forKey:@"golferThreeScoresArray"];
[currentScoreCard setObject:golferFourScores forKey:@"golferFourScoresArray"];
[savedScoreCards setObject:currentScoreCard forKey:@"1"];
NSLog([golferIconsSceneOne objectForKey:@"30101"]);
[userDefaults setObject:savedScoreCards forKey:@"savedScoreCards2"];
[userDefaults synchronize];
NSLog(@"SAVED SCORE CARD");
}