iosswiftxcode6xcasset

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?


Solution

  • This is one way to check it.

    NSString *someString = @"SomeStringFromSomwhere";
    
     if ([UIImage imageNamed: someString])
     { 
        //the image exists..
     } 
     else
     {
        //no image with that name
     }