所以我是Obj-C的新手(具有C和C++经验),我一直在努力.
很简单,我想保存并加载用户进度时的分数和级别.
我有3个功能getFilePath,loadData和savaData.
我getFilePath和loadData似乎工作正常,但我不能获得saveData工作.
这是我的代码:
-(void)saveData
{
NSNumber *updatedScore = [NSNumber numberWithInt:score];
NSNumber *updatedLevel = [NSNumber numberWithInt:level];
NSLog(@"The level im saving is %@",updatedLevel);
NSLog(@"The score im saving is %@",updatedScore);
NSMutableArray *value = [[NSMutableArray alloc]initWithObjects:updatedLevel,updatedScore, nil];
[value writeToFile:[self getFilePath] atomically:YES];
}
-(NSString *)getFilePath
{
NSArray *pathArray = NSSearchPathForDirectoriesInDomains(NSDocumentationDirectory, NSUserDomainMask, YES);
NSLog(@"the path is %@",pathArray);
return [[pathArray objectAtIndex:0]stringByAppendingPathComponent:@"saved.plist"];
}
Run Code Online (Sandbox Code Playgroud)
我的NSLog消息返回正确的值,用户进展级别,但我无法保存它们.