1

I have a set of images inside an .xcassets folder. Using iOS 11 and Xcode 9 I access them with

    func searchCodes() -> NSArray {

    let file = Bundle.main.url(forResource: "PickerStations", withExtension: "plist")
                return NSArray(contentsOf: file!)!
    }

    lineCode = searchCodes().object(at: 1) as? NSDictionary

    //lineFirstInitial is either C,H,J,N,P,D,M,V,B or W
    let lineNameFromInitial = lineCode?.allKeys(for: lineFirstInitial).first as! String

    //lineNameFromInitial is 100% correct value and loaded from an array of Strings. 
//Looped through and each value added to the code below. 
                if let lineLabelImage = UIImage(named: lineNameFromInitial) {
                   lineLabelImageView.image = lineLabelImage
    }

Some Images enter the block and yet others do not as they return nil. However the images are 100% in the .xcassets and the file name is 100% correct. I have tried hardcoding the images name instead of passing the variable lineNameFromInitial but the images are still nil for some despite actually existing.

xcassets

The images are found using the keys in a plist plist

Any suggestions?

RyanTCB
  • 7,400
  • 5
  • 42
  • 62

1 Answers1

1

Two reasons that might be the reason for the images being nil:

1. The images have not been added to your app's target.

enter image description here

2. The images have a name with special characters:

Xcode does not like assets that have special characters like ÄÖÜ etc. in their name. Have a look at the problematic images' names and change those characters to plain old english characters.

joern
  • 27,354
  • 7
  • 90
  • 105