I am trying to create a SwiftUI app that, in one of its functions, saves an image as its pngdata to a class.
class Coupon: Codable, Equatable, Identifiable {
var id = UUID()
var data: [String]
var date: Date
var image: Data
init(name: String, date: String, dateobject: Date, image: UIImage, description: String) {
self.data = [name, date, description]
self.date = dateobject
self.image = image.pngData()!
}
static func == (one: Coupon, two: Coupon) -> Bool {
return one.data == two.data && one.date == two.date
}
}
But whenever I display the image, like this:
Image(uiImage: UIImage(data: coupon.image))
Certain images get rotated upside down.
I've looked in many different answers, but none seem to solve my problem.
Why is this happening, and how do I solve it?