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

标签 iphone ios plist

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

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

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

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

它可以在模拟器上运行,但不能在设备上运行。

你能帮帮我吗?

谢谢!

最佳答案

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

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

关于iphone - 读/写 plist 的正确方法是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3953092/

相关文章:

iphone - View 与 CATransform3D 重叠另一个 View

iphone - iphone 上的 glreadPixels 问题

iphone - 第一 View 警报

ios - 使用 NSFetchedResultsController 返回具有有序关系的对象

ios - Swift 1.2 lowercaseString 与 enumerateSubstringInRange 崩溃

swift - 将 Bool 值保存到 Plist 并更新

iphone - 动画同级 View

iphone - 重构函数错误 - "is not part of the build phase of any targets in the Xcode 3 projects in this workspace and so can' t 被重构”

swift - 使用简单的数据快速编写和读取 plist

swift - UISearchBar textDidChange 来自 plist 的数据