读写plist文件
问题描述:
我需要写入plist文件,然后再读出数据... 但是,每当我测试我的应用程序,写入plist文件的数据永远不会保存退出iPhone模拟器!你能告诉我为什么存在这个问题的原因吗?在运行期间,数据似乎被写入并且完全正确地读取。但我的plist文件从不更新! 我可能做错了。那么你能指导我通过在cocos2d中创建一个plist并读写整数吗? 谢谢!读写plist文件
答
为了节省:
+ (void)save:(Example *)exampleobject {
NSString * directory = [NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES) objectAtIndex:0];
NSString * path = [directory stringByAppendingPathComponent:@"Example.plist"];
[NSKeyedArchiver archiveRootObject:exampleobject toFile:path];
}
要检索
+ (Example *)load {
NSString * directory = [NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES) objectAtIndex:0];
NSString * path = [directory stringByAppendingPathComponent:@"Example.plist"];
NSData * data = [NSData dataWithContentsOfFile:path];
Example * exampleobject = [NSKeyedUnarchiver unarchiveObjectWithData:data];
if (!exampleobject) { exampleobject = [[Example alloc] init]; }
return exampleobject;
}
告诉我们你的代码 – 2012-03-27 20:38:55
让我们看看你的代码;否则这是对问题的完整猜测。 – FluffulousChimp 2012-03-27 20:39:47
你绝对梦想大屁股... – 2012-03-27 20:50:27