Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check if an image exists in Xcode Asset Catalog?

I am fetching JSON data via HTTP and want to display them in a MKMapView with a custom MKAnnotationView. So no problem until here.

Bad thing is the REST service could return types of pins that don't have equivalents in my .xcassets file. Is there any way to check for an entry in the App's Asset Catalog and avoid messages like this:

CUICatalog: Invalid asset name supplied: NonExistingImage, or invalid scale factor: 2.000000

Current code example:

NSString * imageName = @"NonExistingImage";

if (imageName != nil) {
    // this line creates the above message
    UIImage * image = [UIImage imageNamed:imageName]; 

    // checking for image != nil, otherwise use default image
} else {
    // default image
}
like image 914
mvoelkl Avatar asked Oct 21 '22 13:10

mvoelkl


1 Answers

My solution: Seems you call imageNamed with an empty NSString (or nil) this info is being logged. If the image passed simply doesn't exist, resulting UIImage is nil and NO message is created.

like image 125
mvoelkl Avatar answered Nov 01 '22 09:11

mvoelkl