简体   繁体   中英

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
}

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM