我收到以下代码的错误。它来自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)
})
答案 0 :(得分:3)
听起来像Swift试图捕获writeToFile()的返回值并隐式地从闭包中返回它。你只需要明确在这里返回什么。
file.getDataInBackgroundWithBlock({ (data: NSData!, error: NSError!) -> Void in
data.writeToFile(photoPath!, atomically: true)
return
}, progressBlock: { (progress: Int32) -> Void in
println(progress)
})