Mark Bourke
Mark Bourke

Reputation: 10056

Getting images from Cocoapod's xcassets doesn't work

I am using the 1Password Pod and the GCast pod and they both have xcassets files with the assets they want you to use. When I create a button in IB and assign it the name of one of the images in the xcassets file, the correct image shows up but on run-time i get a debug error of: Could not load the "onepassword-button" image referenced from a nib in the bundle with identifier "com.myApp.App"

Any idea what i need to do? Thanks

Upvotes: 5

Views: 900

Answers (1)

Max Desiatov
Max Desiatov

Reputation: 5565

The only way to resolve this that I've found is to specify the image programmatically, not in Interface Builder:

let bundle = NSBundle(forClass: OnePasswordExtension.self)
let image = UIImage(named: "OnePasswordExtensionResources.bundle/onepassword-button", inBundle: bundle,
                    compatibleWithTraitCollection: nil)

Note that you still need to specify the full path to the resource bundle in UIImage initializer, as the bundle value is not the resource bundle itself, but the container framework bundle.

Upvotes: 1

Related Questions