【问题标题】:a warning about func unc createDirectoryAtURL(value of the type '()' ) [closed]关于 func unc createDirectoryAtURL('()' 类型的值)的警告 [关闭]
【发布时间】:2016-07-05 23:25:33
【问题描述】:

我是iOS开发的学习者,今天我尝试编写一些关于FileManger的enter image description here,但是这个方法返回一个类型'()',我该如何解决它?

警告代码如下:

【问题讨论】:

    标签: ios swift nsfilemanager


    【解决方案1】:

    问题是您对createDirectoryAtURL 的调用没有明确的返回值。在 Swift 中,这意味着它返回一个 Void,它由空元组 () 表示。这就是你的调用应该是这样的。

        let temp = NSTemporaryDirectory()
        let newDiretoryURL = NSURL.fileURLWithPath(temp + "/MyNewDirectory")
        try fileManager.createDirectoryAtURL(newDiretoryURL, withIntermediateDirectories: false, attributes: nil)
        print("Success")
      }
    } catch {
      // handle errors here
    }
    

    【讨论】:

    • 非常感谢,对我很有帮助!^.^
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-08-29
    相关资源
    最近更新 更多