我在使用以下代码时遇到错误。它来自 data.writeToFile。我已经尝试过 photoPath、photoPath!、photoPath?,但它总是出错。错误是:getData 调用中的 extraArgument(这不是错误,因为当我注释掉 data.writeToFile 时它工作正常)。
let file = object.objectForKey("image") as PFFile
let photoPath = NSURL.fileURLWithPath(NSTemporaryDirectory())?.URLByAppendingPathComponent("object", isDirectory: true).URLByAppendingPathExtension("jpg")
file.getDataInBackgroundWithBlock({ (data: NSData!, error: NSError!) -> Void in
data.writeToFile(photoPath!, atomically: true)
}, progressBlock: { (progress: Int32) -> Void in
println(progress)
})
请您参考如下方法:
听起来 Swift 正试图捕获 writeToFile() 的返回值并隐式地从闭包中返回它。您只需要明确说明此处返回的内容即可。
file.getDataInBackgroundWithBlock({ (data: NSData!, error: NSError!) -> Void in
data.writeToFile(photoPath!, atomically: true)
return
}, progressBlock: { (progress: Int32) -> Void in
println(progress)
})
