Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Check if string name matches an asset in images.xcassets

Everything I google turns up answers about ALAsset's.

I have an images.xcassets folder and a bunch of assets in there.

I want to know if an asset exists in there based on a string.

E.g. if(images.xcassets.contains("assetName") == true)

Do you know how I can check if an asset exists based on a string?

like image 832
Aggressor Avatar asked Feb 27 '15 21:02

Aggressor


2 Answers

This is one way to check it.

NSString *someString = @"SomeStringFromSomwhere";

 if ([UIImage imageNamed: someString])
 { 
    //the image exists..
 } 
 else
 {
    //no image with that name
 }
like image 54
Earl Grey Avatar answered Nov 04 '22 12:11

Earl Grey


Just a bit more practical answer: Swift

if let myImage = UIImage(named: "assetName") {
  // use your image (myImage), it exists!
}
like image 16
budiDino Avatar answered Nov 04 '22 12:11

budiDino