How to compare 2 Data from UIImagePNGRepresentation?

compare, swift3

Solution

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

Problem

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.

Original source