【问题标题】:createFileAtPath not accepting NSURL anymorecreateFileAtPath 不再接受 NSURL
【发布时间】:2015-10-10 11:39:18
【问题描述】:
    let singleImage = "current.jpg"
    let path = NSURL(fileURLWithPath: NSTemporaryDirectory()).URLByAppendingPathComponent(singleImage)
    let fileManager = NSFileManager.defaultManager()

    fileManager.createFileAtPath(path, contents: imageDataFromURL, attributes: [:])

createFileAtPath 升级到 Swift 2 后停止工作,现在出现以下错误:

无法将“NSURL”类型的值转换为预期的参数类型“字符串”

【问题讨论】:

    标签: swift2 nsurl


    【解决方案1】:

    不幸的是,NSFileManager 没有可在 NSURL 上运行的创建方法。在我的代码中,我尽量避免使用String 进行路径使用,这是我仍然使用NSURL.path 属性回退到路径的少数几个地方之一

    fileManager.createFileAtPath(pathURL.path!, contents: imageDataFromURL, attributes: [:])
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-11-18
      • 2019-05-04
      • 2016-05-22
      • 1970-01-01
      • 2011-04-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多