Nothing above works for Swift3
. Try this for anyone struggling with Swift3 Syntax's
Act:
@IBAction func saveToPhotos(_ sender: AnyObject) { UIImageWriteToSavedPhotosAlbum(yourImageView.image!, self, #selector(image(_:didFinishSavingWithError:contextInfo:)), nil) }
Goal:
func image(_ image: UIImage, didFinishSavingWithError error: Error?, contextInfo: UnsafeRawPointer) { if error == nil { let ac = UIAlertController(title: "Saved!", message: "Image saved to your photos.", preferredStyle: .alert) ac.addAction(UIAlertAction(title: "OK", style: .default, handler: nil)) present(ac, animated: true, completion: nil) } else { let ac = UIAlertController(title: "Save error", message: error?.localizedDescription, preferredStyle: .alert) ac.addAction(UIAlertAction(title: "OK", style: .default, handler: nil)) present(ac, animated: true, completion: nil) } }
See this link for more details. https://www.hackingwithswift.com/read/13/5/saving-to-the-ios-photo-library
Sanju source share