0

i have to fix the follow code for swift2.

if !UIImagePNGRepresentation(img).writeToFile(imagePath, options: nil, error: &error) {
                        if let actualError = error {
                            NSLog("Image not saved. \(actualError)")
                        }
                    }

To compile it i have this error on if row: Cannot invoke writeToFile with an argument list of type (String, options: _, error: inout NSError?)

How I can fix it.

Paolo Gdf
  • 759
  • 3
  • 10
  • 15
  • 3
    For future questions, try to make the title as relevant to the problem as possible. Most users don't have time to click on a vague question and solve a vague problem. This will result in your question not receiving a lot of traffic and you not getting your answer. – Arc676 Nov 04 '15 at 15:02

1 Answers1

0

Try it with

UIImagePNGRepresentation(img)?.writeToFile(imagePath, atomically: true)

instead. Check the Apple Docs.

Edit:

To answer your question more precisely use the error handling in Swift 2.

do {
    try UIImagePNGRepresentation(img)?.writeToFile(imagePath, options: .DataWritingAtomic)
} catch let error as NSError {
    print("Image not saved. \(error.description)")
}
limfinity
  • 726
  • 6
  • 17
  • I'm glad! Please mark my answer as correct than. (Little checkmark beneath the counter on the left.) Thanks. – limfinity Nov 06 '15 at 12:31