Posts

Post not yet marked as solved
0 Replies
758 Views
How can I add an image to CoreData from an imagePickerView. I've watched and viewed a couple of tutorials but they don't explain it well for me.This is the attribute I have created for my image inside of my CoreData model.This is my code I use for my imagePicker:@IBOutlet var imageView: UIImageView! var imagePicker = UIImagePickerController() //MARK: - Image Picker @IBAction func btnClicked(_ sender: UIBarButtonItem) { imagePicker.allowsEditing = false imagePicker.sourceType = .photoLibrary present(imagePicker, animated: true, completion: nil) } func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey : Any]) { if let pickedImage = info[UIImagePickerController.InfoKey.originalImage] as? UIImage { imageView.contentMode = .scaleAspectFit imageView.image = pickedImage } dismiss(animated: true, completion: nil) } func imagePickerControllerDidCancel(_ picker: UIImagePickerController) { dismiss(animated: true, completion: nil) }So the user presses the edit photo button, which brings up the photo gallery. Now once they select this image, I want the image to save to my app. When the app restarts, the image goes back to the original 'edit image' view.
Posted Last updated
.