Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to compare 2 Data from UIImagePNGRepresentation?

Tags:

compare

swift3

I had this in Swift 2.x

let data1 = UIImagePNGRepresentation(self)!
let data2 = UIImagePNGRepresentation(image)!
return data1.isEqualToData(data2)

But now Xcode 8 - Swift 3 tells me:

Value of type 'Data' has no member 'isEqualToData'

I also tried using data1.isEqual(to: data2) but it doesn't change much.

like image 900
Kalzem Avatar asked Oct 27 '16 20:10

Kalzem


1 Answers

This is Swift, not objective C. In Swift if a type conforms to the Equatable protocol (and Data is Equatable), then you use operator == to compare two instances and not .isEqaul:

return data1 == data2
like image 108
Josh Homann Avatar answered Dec 31 '22 18:12

Josh Homann