我是 iPhone 新手
我已经存储了GameData.plist 文件,并且在“root”字典下的“root”字典下我有一个名为“gameProgress”的数组,我想在这个“gameProgress”数组中插入数据。
以下是我的代码
-(void)writeDataToPhone
{
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *plistPath = [documentsDirectory stringByAppendingPathComponent:@"storedGameData.plist"];
// read or create plist
NSMutableDictionary *dict;
NSFileManager *fileManager = [NSFileManager defaultManager];
if ( [fileManager fileExistsAtPath:plistPath] ) {
// Reading the Plist from inside the if
//statement
NSLog(@"dictionary existed, reading %@", plistPath);
dict = [NSMutableDictionary dictionaryWithContentsOfFile:plistPath];
}
NSNumber *newNumberOfCompletedLevels = [NSNumber numberWithInt:1];
[dict setObject:newNumberOfCompletedLevels forKey:@"gameProgress"];
NSLog(@"writing to %@…", plistPath);
[dict writeToFile:plistPath atomically:YES];
NSLog(@"dictionary values are…:");
for (id key in dict) {
NSLog(@"key=%@, value=%@", key, [dict objectForKey:key]);
}
}
但我的数组是空白的,没有插入任何内容
我的代码有什么问题?以及我应该在我的代码中更改什么以在数组中插入值