iPhone - Writing a dictionary to file : handling errors

家住魔仙堡 提交于 2019-12-10 22:22:04

问题


When saving a NSDictionary to file using :

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

YES or NO can be returned.

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

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


回答1:


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.



来源:https://stackoverflow.com/questions/5806425/iphone-writing-a-dictionary-to-file-handling-errors

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!