When I add a bundle target to my project and link the image with a new asset catalog to bundle,
It is failed to instantiate UIImage from the asset catalog in the bundle that I created in iOS 12 or below (iOS 13 works fine).
This error occurred only in Xcode 11
In short,
Build to iOS 13 in Xcode 11: Successfully image loaded.
Build to iOS 12 or iOS 11 in Xcode 11: Failed to load the image.
Build to iOS 12 or iOS 11 in Xcode 10.3: Successfully image loaded.
I've attached the sample app to simulate: https://github.com/momamene/AssetCatalogImageSampleApp
The core code is shown below.
import UIKit
class CustomBundleViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
let resourcePath = Bundle.main.path(
forResource: "CustomBundle",
ofType: "bundle"
)!
let bundle = Bundle(path: resourcePath)!
// NOTE: image is nil on iOS 12 and iOS 11
let image = UIImage(named: "sample-image", in: bundle, compatibleWith: nil)
let frame = CGRect(x: 100, y: 100, width: 100, height: 100)
let imageView = UIImageView(frame: frame)
imageView.image = image
view.addSubview(imageView)
}
}
I think this is absolutely a bug of Xcode 11.