How to conform UIImage to Codable?

Properly the easiest way is to just make the property Data instead of UIImage like this: public struct SomeImage: Codable { public let photo: Data public init(photo: UIImage) { self.photo = photo.pngData()! } } Deserialize the image: UIImage(data: instanceOfSomeImage.photo)!

How to capture UIView to UIImage without loss of quality on retina display

Switch from use of UIGraphicsBeginImageContext to UIGraphicsBeginImageContextWithOptions (as documented on this page). Pass 0.0 for scale (the third argument) and you’ll get a context with a scale factor equal to that of the screen. UIGraphicsBeginImageContext uses a fixed scale factor of 1.0, so you’re actually getting exactly the same image on an iPhone 4 as … Read more