小编rep*_*guy的帖子

将对象设置为NSMutableDictionary且没有崩溃日志时,应用程序崩溃

我尝试为我的游戏制作一个简单的分数系统,我正在使用字典并使用NSUserDefaults保存它来存储玩家的分数.但是,当我尝试将新分数设置为现有键/值时,应用程序崩溃,没有任何控制台日志消息,并且xcode切换到不可读的汇编程序代码.我知道崩溃的地方,因为我设置了异常,它显示了它被调用的行.如果改变了什么,我也会使用cocos2d.

这是代码:

//creates key for the right level     
NSString *currentLevelString = [NSString stringWithFormat:@"Level%i",numberOfCurentLevel];


 //checking if dictionary is empty, if empty then it means the game is played for the first time
 NSMutableDictionary *dictionary = [[[NSMutableDictionary alloc]init]autorelease];
//ud is the UserDefaults

 dictionary = [ud objectForKey:@"dictionaryWithScores"];

 if ([dictionary objectForKey:@"Level5"] == nil) {
     //assigning first values for empty dictionary
     dictionary = [NSMutableDictionary dictionaryWithContentsOfFile:[[NSBundle mainBundle]pathForResource:@"ScoreList" ofType:@"plist"]];
     NSLog(@"dictionary was empty");
 }
 //NSLog(@"now dictionary shoud not be empty %@",dictionary);
 //calculating current score for this level
 double …
Run Code Online (Sandbox Code Playgroud)

xcode objective-c nsdictionary cocos2d-iphone nsmutabledictionary

0
推荐指数
1
解决办法
1278
查看次数