如何修复可可足类中丢失的资产

时间:2018-12-24 11:16:10

标签: ios swift cocoapods

我正在创建一个cocoapod sdk,我的podspec文件在这里丢失了我的资产:

s.resource_bundles = { 'Project' => ['Project/Assets/*.xcassets'] }

每当我尝试加载资产时,我也会收到此警告

CUIThemeStore: No theme registered with id=0

我用来访问资产的代码:

image.image = UIImage(named: "Rectangle")

我尝试检查资产文件目标成员身份,并且将其设置为Project-Project

是正确的

1 个答案:

答案 0 :(得分:0)

尝试从自己的捆绑软件中显式访问资产:

final class Project: NSObject {
   private static let frameworkBundle = Bundle(for: Project.self)
   static let path = frameworkBundle.path(forResource: "Project", ofType: "bundle")!
   static let bundle = Bundle(path: path)!
}

extension UIImage {
  /// get an image from the project bundle
  static func fromPodBundle(_ name: String) -> UIImage? {
    return UIImage(named: name, in: Project.bundle, compatibleWith: nil)
  }
}

image.image = UIImage.fromPodBundle("Rectangle")