如何从使用 writeToFile 创建的文件加载 NSDictionary? [英] How to load an NSDictionary from a file created with writeToFile?

查看:49
本文介绍了如何从使用 writeToFile 创建的文件加载 NSDictionary?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 NSMutableDictionary,我使用

I have an NSMutableDictionary, and I wrote it using

[stuff writeToFile:@"TEST" atomically:YES];

我以后如何检索它?

另外,如果我决定用 4S 替换我的 iPhone 4 会怎样?我的写入数据可以转移吗?

Also, what would happen if I decide to replace my iPhone 4 with the 4S? Can my piece of written data be transferred?

推荐答案

我想你想要这样的:

[[NSMutableDictionary alloc] initWithContentsofFile:[self dataFilePath]];

您确实需要获取正确的路径来存储和检索您的文件,沿着这个例程:

You do need to obtain the correct path to store and retrieve your file, along the lines of this routine:

- (NSString *)dataFilePath {
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentsDirectory = [paths objectAtIndex:0];
    return [documentsDirectory stringByAppendingPathComponent:@"TEST"];
}

这篇关于如何从使用 writeToFile 创建的文件加载 NSDictionary?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆