私は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]);
}
}
しかし、私の配列は空白です何も挿入されていません
私のコードの問題は何ですか?配列に値を挿入するには、コードで何を変更する必要がありますか