1 Reply
      Latest reply on Jul 17, 2018 1:59 AM by eskimo
      El Kal Level 1 Level 1 (0 points)

        I want to save an image for persistence through adopting Codable protocol. Kindly help to do so.

        • Re: Can I save an image using codable protocol, if so, how?
          eskimo Apple Staff Apple Staff (10,015 points)

          The most straightforward way to do this would be to write your own implementations of the Codable methods that convert between the image and data (using UIImagePNGRepresentation or UIImageJPEGRepresentation to go one way and UIImage(data:) to go the other).

          However, you should think carefully before doing down that path.  Serialised images tend to be large and many of the serialisation formats associated with Codable don’t deal well with very large blobs of data.  You may be better off saving the image in a separate file and then have your Codable implementation reference that.

          Share and Enjoy

          Quinn “The Eskimo!”
          Apple Developer Relations, Developer Technical Support, Core OS/Hardware
          let myEmail = "eskimo" + "1" + "@apple.com"