fileManager.createFileAtPath always fails

前端 未结 2 640
-上瘾入骨i
-上瘾入骨i 2020-12-19 06:33

I try to call the fileManager.createFileAtPath-method, but it always fails. My variable success is always false. I looked at some simi

2条回答
  •  执笔经年
    2020-12-19 07:38

    Here is a problem:

    if fileManager.fileExistsAtPath(String(pListPath), isDirectory: &isDir)
    

    You cannot use String(...) to convert a NSURL to a file path string, you have to use the path method:

    if fileManager.fileExistsAtPath(pListPath.path!, isDirectory: &isDir)
    

    If reportsPath is also an NSURL then the same problem exists at

    pListPath = NSURL(fileURLWithPath: String(reportsPath)).URLByAppendingPathComponent("myReports.plist", isDirectory: false)
    

    which should be

    let pListPath = reportsPath.URLByAppendingPathComponent("myReports.plist", isDirectory: false)
    

提交回复
热议问题