Advertisement
neatekFb

Compare 2 UIImage's // swift 3

Dec 2nd, 2016
170
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Swift 0.57 KB | None | 0 0
  1. //// Vladimir Zhelnov - neatek.pw - Web/iOS dev
  2. func image(image1: UIImage, isEqualTo image2: UIImage) -> Bool {
  3.     let data1: NSData = UIImagePNGRepresentation(image1)! as NSData
  4.     let data2: NSData = UIImagePNGRepresentation(image2)! as NSData
  5.     return data1.isEqual(data2)
  6. }
  7. // or extension (better)
  8. extension UIImage {
  9.     func isEqualToImage(image: UIImage) -> Bool {
  10.         let data1: NSData = UIImagePNGRepresentation(self)! as NSData
  11.         let data2: NSData = UIImagePNGRepresentation(image)! as NSData
  12.         return data1.isEqual(data2)
  13.     }
  14.    
  15. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement