0
我的iPhone應用程序崩潰,並使用此代碼時收到EXC_BAD_ACCESS錯誤:EXC_BAD_ACCESS - iPhone
NSError *error;
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); //1
NSString *documentsDirectory = [paths objectAtIndex:0]; //2
NSString *path = [documentsDirectory stringByAppendingPathComponent:@"stats.plist"]; //3
NSFileManager *fileManager = [NSFileManager defaultManager];
if (![fileManager fileExistsAtPath: path]) //4
{
NSString *bundle = [[NSBundle mainBundle] pathForResource:@"stats" ofType:@"plist"]; //5
[fileManager copyItemAtPath:bundle toPath: path error:&error]; //6
[bundle release];
}
NSMutableDictionary *savedStock = [[NSMutableDictionary alloc] initWithContentsOfFile: path];
//load from savedStock example int value
score.highScore = [[savedStock objectForKey:@"score"] intValue];
score.deaths = [[savedStock objectForKey:@"deaths"] intValue];
score.iFallPoints = [[savedStock objectForKey:@"iFallPoints"] intValue];
score.difficulty = [[savedStock objectForKey:@"difficulty"] intValue];
[savedStock release];
得分是我訪問的單身。
堆棧跟蹤也會有幫助 – bioffe 2010-10-26 13:37:53
不要釋放捆綁! – Alin 2010-10-26 13:41:50