I need to get the value of a UIImage’s image as a string.
Previously I was doing:
if(images[imageNo].image == [UIImage imageNamed:@"image1.png"])
{
But now I have a lot more conditions so I would like to use a switch, doing:
switch(images[imageNo].image)
{
case @"image1.png":
break;
}
Is there a way to achieve this? Thanks!
Both of your approaches are incorrect. The first one relies on caching (which is not documented), meanwhile the second is a syntax error – the ‘case’ keywords expect a compile-time constant expression.
As far as I know, there’s no such a method in the iOS SDK that would return an image’s filename – simply because it’s not a property of the image (what would it return for a programmatically created image?). You should instead try to operate on an NSDictionary, storing the UIImage objects associated with the filenames as keys, and comparing the keys using
isEqualToString:.So you should create your images only once, and store them in a dictionary: