【发布时间】:2010-10-28 16:17:52
【问题描述】:
我在资源文件夹中创建了 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。我对这个概念很陌生。所以如果有人知道,请帮助我。 提前致谢。 :-)
【问题讨论】:
-
您可能应该在 iOS 参考库中阅读Property List Programming Guide。
标签: iphone objective-c cocoa