我正在尝试从资源(图标)创建UIImage
。我的代码大致是:
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
总是零。打印出捆绑包:
Optional(NSBundle </Users/user/Library/Developer/Xcode/DerivedData/MyModule-dxpuooiqxaovvrbdrptwxiypbvwh/Build/Products/Debug-iphonesimulator/MyModule.framework/MyModule.bundle> (not yet loaded))
路径有效(我ls
编辑)。另请注意not yet loaded
。我尝试重置模拟器。我也试过bundle?.load()
,但结果是:
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)
请注意not loaded
。我还尝试删除DerivedData
。
有什么想法吗?