-2

I'm trying to assign a profile picture in app through a UIImagePickerController. However, I need to figure out a way to store the image so it still appears after the apps restarts.

I've tried other methods, primarily the ones that use UIImagePNGRepresentation. But this no longer exists in Swift 4+, so I need some other method.

   func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey : Any])
    {
        picker.dismiss(animated: true)

        profilePicture = info[.editedImage] as! UIImage
    }
}

What I want to do, is still display the image as a profile picture. But when the app restarts, still have the image appear. Since this is from the camera roll, I can't store it in the .xcassets

rmaddy
  • 298,130
  • 40
  • 468
  • 517
  • Possible duplicate of [Saving image and then loading it in Swift (iOS)](https://stackoverflow.com/questions/37344822/saving-image-and-then-loading-it-in-swift-ios) – Mr.P Apr 12 '19 at 15:44

1 Answers1

-1

Let's assume that this really is how you are getting your image:

profilePicture = info[.editedImage] as! UIImage

OK, so at that moment you know what the image is. So store it to disk at a known location (e.g. Documents) under a known name. On future launches, all you have to do is look to see if the image is there and use it if it is.

primarily the ones that use UIImagePNGRepresentation. But this no longer exists in Swift 4+

Yes, it does, and that is the way to extract the data and store it to disk. All that has happened is that the name has changed and it is now a UIImage method.

https://developer.apple.com/documentation/uikit/uiimage/1624096-pngdata

matt
  • 447,615
  • 74
  • 748
  • 977