Xcode 11: Failed to instantiate image from asset catalog (.car file) in a custom bundle on iOS 13

Viewed 1702

Our iOS app has a custom bundle that has an assets catalog (.car file). This has been the setup since iOS 9. Fetching image assets and using them has not been an issue until now with iOS 13 on Xcode 11 (not sure if it works when app is built with xcode 10 and run on iOS 13).

This is how the bundle is used in the app: screenshot

The bundle is fetched using this code:

let bundlePath = Bundle.main.path(forResource: "TheResource", ofType: "bundle")!
var bundle = Bundle(path: bundlePath)

Now when I print this bundle variable I get the following:

(lldb) po bundle
▿ Optional<NSBundle>
  - some : NSBundle </Users/xyz/Library/Developer/CoreSimulator/Devices/SE8C7E9D-76AF-4564-B21B-78DC990F3D2E/data/Containers/Bundle/Application/PD422A04-B4C8-42F0-A5CB-9465AC70D3A2/abc.app/TheResource.bundle> (not yet loaded)
(lldb) po bundle.loadAndReturnError()
Error Domain=NSCocoaErrorDomain Code=4 "The bundle “TheResource” couldn’t be loaded because its executable couldn’t be located." UserInfo={NSLocalizedFailureReason=The bundle’s executable couldn’t be located., NSLocalizedRecoverySuggestion=Try reinstalling the bundle., NSBundlePath=/Users/xyz/Library/Developer/CoreSimulator/Devices/SE8C7E9D-76AF-4564-B21B-78DC990F3D2E/data/Containers/Bundle/Application/PD422A04-B4C8-42F0-A5CB-9465AC70D3A2/abc.app/TheResource.bundle, NSLocalizedDescription=The bundle “TheResource” couldn’t be loaded because its executable couldn’t be located.}

This is the response I get on both a iOS 12 device and a iOS 13 device. But the assets load fine on iOS 12.

I have tried the following things to no avail:
1. Since there is an issue with Xcode 11 throwing the multiple paths generating the same file error, I renamed the .car assets catalog from Assets.car to something more descriptive.
2. called .load() on the bundle variable to try and load it since it kept saying not loaded.
3. Tried to load images with extension, also tried adding some traits and use the UIImage(named: <name>, in: <bundle>, compatibleWith: <traits>) method.

Found this question on apple forum but thats little different than the behavior I am seeing.

Have no idea why the assets load fine when the app is built with Xcode 11 and run on iOS 12 but do not load when run on iOS 13 devices/simulators.

Any help would be appreciated, I am dumbfounded by this issue. Thanks!

1 Answers

Is the name you're using to load case-sensitive exact to the asset catalog name?

Ran into this problem migrating to Xcode 11 and the problem was in essence

UIImage(named: "fooImage"...

when the actual name in the catalog was "FooImage".

So check your case-sensitive names first...

Related