9

I'm trying to create an UIImage from an asset (icon). My code is roughly:

public class MyModule: NSObject {
}

let classBundle = NSBundle(forClass: MyModule.self)
let bundleURL = classBundle.URLForResource("WeatherUI", withExtension: "bundle")
let bundle = NSBundle(URL: bundleURL!)
print(bundle)

// "foo" corresponds to foo.imageset
let image = UIImage(named: "foo", inBundle: bundle, compatibleWithTraitCollection: nil)

image is alway nil. Printing out bundle:

Optional(NSBundle </Users/user/Library/Developer/Xcode/DerivedData/MyModule-dxpuooiqxaovvrbdrptwxiypbvwh/Build/Products/Debug-iphonesimulator/MyModule.framework/MyModule.bundle> (not yet loaded))

The path is valid (I lsed it). Also note the not yet loaded. I tried resetting the simulator. I also tried bundle?.load(), but this results in:

2016-07-15 15:55:24.051 MyModule_Example[25549:306130] Cannot find executable for CFBundle 0x7fc204880770 </Users/user/Library/Developer/Xcode/DerivedData/MyModule-dxpuooiqxaovvrbdrptwxiypbvwh/Build/Products/Debug-iphonesimulator/MyModule.framework/MyModule.bundle> (not loaded)

Note the not loaded. I also tried deleting DerivedData.

Any ideas?

Steve Kuo
  • 61,876
  • 75
  • 195
  • 257

0 Answers0