我已经在资源文件夹中创建了save.plist。我直接在其中写入了一些数据(无需使用编码)。我能够读取该数据,但无法通过代码将其写入相同的save.plist。通过使用以下代码,我试图写入数据,但是数据被存储在我的.app plist中。代码在这里
NSString *errorDesc = nil;
NSPropertyListFormat format;
NSString *plistPath = [[NSBundle mainBundle] pathForResource:@"save" ofType:@"plist"];
NSData *plistXML = [[NSFileManager defaultManager] contentsAtPath:plistPath];
NSMutableDictionary *temp = (NSMutableDictionary *)[NSPropertyListSerialization
propertyListFromData:plistXML
mutabilityOption:NSPropertyListMutableContainersAndLeaves
format:&format errorDescription:&errorDesc];
if (!temp) {
NSLog(errorDesc);
[errorDesc release];
}
// [temp setValue:@"123" forKey:@"line1"];
// [temp writeToFile:plistPath atomically: YES];
//Reading data from save.plist
NSLog([temp objectForKey:@"name"]);
NSLog([temp objectForKey:@"wish"]);
NSNumber *num=[temp valueForKey:@"roll"];
int i=[num intValue];
printf("%d",i);
//writitng the data in save.plist
[temp setValue:@"green" forKey:@"color"];
[temp writeToFile:plistPath atomically: NO];
NSMutableDictionary *temp1 = (NSMutableDictionary *)[NSPropertyListSerialization
propertyListFromData:plistXML
mutabilityOption:NSPropertyListMutableContainersAndLeaves
format:&format errorDescription:&errorDesc];
NSLog([temp objectForKey:@"color"]);
我想要的是,我要写入的数据应仅写入存储在引用中的save.plist中。我是这个概念的新手。因此,如果有人知道,请帮助我。提前致谢。:-)
慕神8447489
相关分类