【发布时间】:2016-05-06 07:31:03
【问题描述】:
我尝试调用fileManager.createFileAtPath-方法,但总是失败。
我的变量success 始终是false。我在这里查看了一些类似的帖子,但没有完全符合我的需求。
这是我的代码:
pListPath = NSURL(fileURLWithPath: String(reportsPath)).URLByAppendingPathComponent("myReports.plist", isDirectory: false)
let data: NSData = NSData()
var isDir: ObjCBool = false
if fileManager.fileExistsAtPath(String(pListPath), isDirectory: &isDir)
{
print("File already exists")
}
else
{
let success = fileManager.createFileAtPath(String(pListPath), contents: data, attributes: nil)
print("Was file created?: \(success)")
print("plistPath: \(pListPath)")
}
这是我尝试解决此问题的方法:
我尝试使用该方法
let success = NSFileManager.defaultManager().createFileAtPath(String(pListPath), contents: data, attributes: nil)
还有
let success = data.writeToFile(String(pListPath), atomically: true)
但是没有任何效果。 success总是false。
我还尝试给它一个文字字符串作为路径,将contents设置为nil,我什至将我想将其放入777的目录权限更改为,但注意到有效。 success总是假的。我希望你能帮我解决这个问题。
任何帮助都非常感谢。谢谢
【问题讨论】:
-
请显示您使用的是什么路径?
reportsPath和pListPath
标签: ios swift nsfilemanager