-1

I am trying to check if the filename of the image loaded in the imageView is equal to a certain string.

For example with parse i did it this way:

if let user = PFUser.currentUser(){
            if let imageData = user["profilePic"] as? PFFile {     // ? Optional because there can be no image uploaded yet.

if imageData.name.containsString("avatarImageFile"){     //If was not the avatar image then continue
                //Mark: If latest profile pic uploaded was the avatar image then do this
                profileLable.text = "Upload Profile Picture"

Now I'm trying to do that with an image in the image view but cannot find any property to help me find the file name string. So i tried this but not working either.

 let img = imagePreview.image

  //  let imgData = UIImageJPEGRepresentation(img!, 0.1)
    if img!.isEqual(UIImage(contentsOfFile: "gallery-icon after tap.jpg")){
          print("not to be parsed")
    }else {

        print("to be parsed")
    }

Anybody knows a way to compare the filename string contents of the image file that is in the image view.

Kegham K.
  • 1,589
  • 22
  • 40
  • possible duplicate of http://stackoverflow.com/questions/1740274/uiimageview-how-to-get-the-file-name-of-the-image-assigned – TPlet Jan 18 '16 at 14:15
  • Maybe overkill and does not fit your requirements but what about compute hash of your image and use equal on this hash? – Martin Makarsky Jan 18 '16 at 14:41

1 Answers1

2

Since a UIImage may not come from a file representation, it has no reason to have a file name as a property.

If you need that ability, consider creating a FileImage subclass for instances that are specifically loaded from a file. That way you can remember the name and code your own equality conditions.

Phillip Mills
  • 30,888
  • 4
  • 42
  • 57