Error handling swift2中的错误处理
我必须修复swift2的以下代码Error handling swift2中的错误处理,error-handling,swift2,xcode7,uiimagepngrepresentation,Error Handling,Swift2,Xcode7,Uiimagepngrepresentation,我必须修复swift2的以下代码 if !UIImagePNGRepresentation(img).writeToFile(imagePath, options: nil, error: &error) { if let actualError = error { NSLog("Image not saved. \(actualError)")
if !UIImagePNGRepresentation(img).writeToFile(imagePath, options: nil, error: &error) {
if let actualError = error {
NSLog("Image not saved. \(actualError)")
}
}
要编译它,如果行:无法使用类型为的参数列表调用writeToFile
(字符串,选项:u,错误:inout NSError?
我如何修复它。用
UIImagePNGRepresentation(img)?.writeToFile(imagePath, atomically: true)
相反。检查一下
编辑:
要更准确地回答您的问题,请使用
对于将来的问题,尽量使标题与问题相关。大多数用户没有时间点击一个模糊的问题并解决一个模糊的问题。这将导致你的问题没有收到大量的流量,你没有得到你的答案。我很高兴!请把我的答案标记为正确。(左边柜台下面的小勾号)谢谢。
do {
try UIImagePNGRepresentation(img)?.writeToFile(imagePath, options: .DataWritingAtomic)
} catch let error as NSError {
print("Image not saved. \(error.description)")
}