I need to check if a file loaded into an UIImage object file is equal to another image and execute some actions if so. Unfortunately, it\'s not working.
You cannot compare two UIImage objects using the != or == operators, one option is comparing as NSData using the UIImagePNGRepresentation to convert it to NSData objects, like in the following code:
func areEqualImages(img1: UIImage, img2: UIImage) -> Bool {
guard let data1 = UIImagePNGRepresentation(img1) else { return false }
guard let data2 = UIImagePNGRepresentation(img2) else { return false }
return data1.isEqualToData(data2)
}
I hope this help you.