writeToFile失败-如何调试为什么会失败(使用哪些工具)? [英] writeToFile fails - how do I debug WHY it fails (what tools)?

查看:71
本文介绍了writeToFile失败-如何调试为什么会失败(使用哪些工具)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在从JSON获取NSDictionary(使用SBJson),我想存储它.我正在使用

I'm getting an NSDictionary from JSON (using SBJson), and I want to store it. I'm using

[liveData writeToFile:localFilePath atomically:YES]

,并且失败.数据看起来就像它的所有NSString,NSDictionary和NSArray(按原子方式:是"所要求的).我在其他地方使用了相同的localFilePath.

and it fails. The data looks like its all NSString, NSDictionary, and NSArray (which "atomically:YES" demands). I used the same localFilePath elesewhere.

所以我的问题是:如何找出问题出在哪里?我可以使用哪些工具来了解为什么writeToFile失败?日志未显示错误消息.

So my question is: how can I find out where the problem is? What tools can I use to understand why writeToFile fails? The log doesn't show an error message.

推荐答案

它可能有多种原因:

  • 您正在写入的路径是错误的,不可写的(您没有写访问权限),或者父目录不存在(如果 localFilePath 是"/path/to/file.plist",但目录"/path/to/"不存在,它将失败)
  • liveData词典确实包含不是PropertyList对象的对象.仅 NSData NSDate NSNumber NSString NSArray NSDictionary 对象可以写入属性列表文件(并且 writeToFile:atomically: do 写入plist文件,因此字典 do 必须仅包含PList对象,该方法才能成功)
  • The path you are writing to is wrong, not writable (you don't have write access to it), or the parent directory does not exists (if localFilePath is "/path/to/file.plist" but the directory "/path/to/" does not exists, it will fail)
  • The liveData dictionary does contains objects that are not PropertyList objects. Only NSData, NSDate, NSNumber, NSString, NSArray, or NSDictionary objects can be written into a Property List file (and writeToFile:atomically: do write to a plist file so the dictionary do have to contains only PList objects for that method to succeed)

这篇关于writeToFile失败-如何调试为什么会失败(使用哪些工具)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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