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)!