I am creating a private library that includes resources that are referenced by components in the library. The library is shared with apps using CocoaPods. In the .podspec for
This answer works with Swift3 and Swift4.
Create a function under the pod directory into the file.
func loadImageBundle(named imageName:String) -> UIImage? {
let podBundle = Bundle(for: self.classForCoder)
if let bundleURL = podBundle.url(forResource: "Update with directory name", withExtension: "bundle")
{
let imageBundel = Bundle(url:bundleURL )
let image = UIImage(named: imageName, in: imageBundel, compatibleWith: nil)
return image
}
return nil
}
Usage
imageView.image = loadImageBundle(named: "imagefile")