Search code examples
iosswiftxcode8xcasset

can not load image from xcassets by using code, but xib can


Previous developer using R.swift to load resources.

And I delete it from Cocoapods, then I using

let image = UIImage.init(named: "testimage") 

to load image from xcassets, and it return nil.

And I load testimage in xib, it works.

I have no idea why I can't load resources from xcassets by using code.

xcassets

code

ib

imageLiteral


Solution

  • Just use:

    let image = UIImage(named: "imageNameInAssets")