iPhone - 将字典写入文件:处理错误 [英] iPhone - Writing a dictionary to file : handling errors

查看:130
本文介绍了iPhone - 将字典写入文件:处理错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用以下方式将NSDictionary保存为文件:

When saving a NSDictionary to file using :

- (BOOL)writeToFile:(NSString *)path atomically:(BOOL)flag

是或否可以退回。

有一些编写接受NSError参数的文件的方法。

在NSDictionary的情况下,这种方法不存在。

There are some methods for writing files that accept a NSError parameter.
In the case of the NSDictionary, such a method doesn't exist.

所以如果 writeToFile 方法返回NO,我该怎么知道发生了什么?

So if the writeToFilemethod returns NO, how may I know what happened ?

推荐答案

查看 writeToFile:atomically:的文档,以查看哪些数据类型可以在字典中当你使用这种方法。如果您不包含这些基本类型(例如您自己的对象)中的对象,则该方法将返回NO。在这种情况下,要保存这些类型的对象,您必须寻找其他方式来编写数据,例如使用NSArchiver并使对象符合NSCoding协议。

Look at the docs for writeToFile:atomically: to see which data types can be in a dictionary when you use this method. If you include an object not among these basic types (such as your own object), the method will return NO. In this case, to save these kinds of objects, you have to look to other means to write the data, such as using an NSArchiver and making your objects conform to the NSCoding protocol.

这篇关于iPhone - 将字典写入文件:处理错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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