views:

45

answers:

1

Hi all, i have a question, totally newbie but i would like to know how can i get to compare and image in an if else statement?

i have an image lets say it is "img.png" and i have it displayed in an imageview already in the application, however in the codes i would like to compare if the image show is "img.png"

I understand that for string we use the isEqualToString:, so if it's for an image what would i use?

example would be :

if ([img.image isEqual:@"img.png"])

What i've typed is something like this but it isnt working. could anyone point me in the right direction? thanks alot

Much appreciated!

+1  A: 

If you first got the image using [UIImage imageNamed:@"img.png"] you could compare the image object pointers: if (img.image == [UIImage imageNamed:@"img.png"]).

But: I'd consider this bad design and would rather use another way of identifying images, like storing the name of the image in another instance variable.

Nikolai Ruhe
[UIImage imageNamed:@"img.png"] will unnecessarily load UIImage into memory if it was not loaded so using separate instance variable is much much better I think.
Vladimir
@nikolai thank you for your reply (: i've gotten an idea on how to do it let me try and i'll get back!@vladmir thanks for pointing about the memory (:
malvin