James. H
James. H

Reputation: 1

Cocoapods framework: Assets is in different bundle with framework's bundle

I have a framework mixed Objective-C and Swift using CocoaPods for distribution. The issue is it cannot load images stored in the framework's Assets.

This is the code I used to load the image:

let currentBundle = Bundle(for: <MyClass>.self)
let image1 = UIImage(named: "someImage", in: currentBundle, compatibleWith: nil)

The image1 returns nil. After some trials, it worked with the code below:

let bundleWithIdentifier = Bundle(identifier: "org.cocoapods.MyFramework")
let image2 = UIImage(named: "someImage", in: bundleWithIdentifier, compatibleWith: nil)

currentBundle and bundleWithIdentifier are not the same bundles.

'org.cocoapods.MyFramework' is the identifier of this framework generated in the hosted app after running pod install. The original identifier is: "com.be.MyFramework".

This is part of the podspec file used to store assets in the resource bundle:

spec.subspec 'Core' do |core|
    core.source_files = '<MyFramework>/**/*.{h,m,swift}'
    core.public_header_files = '<MyFramework>/<MyFramework>.h',
    core.frameworks = 'UIKit', 'Foundation', 'Security', 'QuartzCore'
    core.library = 'c++'
    core.resource_bundles = {
      '<MyFramework>' => ['<MyFramework>/**/*.{xcassets,xib,storyboard,png,jpg,lproj}']
    }
end

I have another framework, the podspec file, and everything is the same except this framework was mixed with Swift and Objective-C. The other framework can load images without any issues using Bundle(for: .self). Can someone help me explain why there are differences even though the two frameworks are almost the same?

Upvotes: 0

Views: 40

Answers (0)

Related Questions