I am writing my first iOS application (iPhone only) with Swift. The main application view should allow user to choose the image from the photo gallery.
I\'ve found
@IBAction func ImportImage(_ sender: Any)
{
let image = UIImagePickerController()
image.delegate = self
image.sourceType = UIImagePickerController.SourceType.photoLibrary
image.allowsEditing = false
self.present(image, animated: true)
{
//After it is complete
}
}
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey : Any]) {
if let image = info[UIImagePickerController.InfoKey.originalImage] as? UIImage
{
myimage.image = image
}
else{
//
}
self.dismiss(animated: true, completion: nil)
do {
try context.save()
} catch {
print("Could not save. \(error), \(error.localizedDescription)")
}
}
Add UINavigationControllerDelegate
, UIImagePickerControllerDelegate
delegates in the class definition