读/写plist的正确方法是什么?

时间:2010-10-17 11:56:09

标签: iphone ios plist

在我的应用程序中,我将一些用户数据存储在两个已包含一些数据的.plist文件中,但用户可以更改它。

NSString *Path = [[NSBundle mainBundle] bundlePath];

NSString *DataPath = [Path stringByAppendingPathComponent:@"Settings.plist"];

NSMutableDictionary *tempDict = [[NSMutableDictionary alloc] initWithContentsOfFile:DataPath];

它适用于模拟器,但不适用于设备。

请帮帮我吗?

谢谢!

1 个答案:

答案 0 :(得分:2)

您无法写入设备上的软件包,因此您需要获取文档或库目录的路径。

- (NSString*)applicationDocumentsDirectory
{
        NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
        return [paths lastObject];
}