简体   繁体   English

如何检查Xcode Asset Catalog中是否存在图像?

[英]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. 我通过HTTP获取JSON数据,并希望使用自定义MKAnnotationView在MKMapView中显示它们。 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. 糟糕的是REST服务可能会返回我的.xcassets文件中没有等效项的引脚类型。 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 CUICatalog:提供的资产名称无效:NonExistingImage或无效比例因子: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. 我的解决方案:似乎你用一个空的NSString(或nil)调用imageNamed这个信息被记录下来。 If the image passed simply doesn't exist, resulting UIImage is nil and NO message is created. 如果简单地通过了图像不存在时,所得的UIImage是零,并创建NO消息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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