Hello,
We are modularizing our iOS project using SPM. One of those modules is our UI module, which contains a bunch of Resources, for example, custom fonts.
In order to register the fonts, we use the following code to access the resources:
This is the recommended way from Apple as seen here.
This seems to be working when importing the module into our main app.
The problem appears when this code is executed from a Playground within the same module. When the code is executed, a fatal error is thrown:
This is triggered from the generated file resource_bundle_accessor.swift which contains the following code:
Lastly, our module target defines resources like so:
Is there any workaround so we don't trigger the fatalError when executing that code from a playground? Any check to know if Bundle.module is available?
Thank you
We are modularizing our iOS project using SPM. One of those modules is our UI module, which contains a bunch of Resources, for example, custom fonts.
In order to register the fonts, we use the following code to access the resources:
Code Block swift Bundle.module.urls(forResourcesWithExtension: "otf", subdirectory: nil)
This is the recommended way from Apple as seen here.
This seems to be working when importing the module into our main app.
The problem appears when this code is executed from a Playground within the same module. When the code is executed, a fatal error is thrown:
Code Block unable to find bundle named UniverseUI_UniverseUI
This is triggered from the generated file resource_bundle_accessor.swift which contains the following code:
Code Block swift import class Foundation.Bundle private class BundleFinder {} extension Foundation.Bundle { /// Returns the resource bundle associated with the current Swift module. static var module: Bundle = { let bundleName = "UniverseUI_UniverseUI" let candidates = [ // Bundle should be present here when the package is linked into an App. Bundle.main.resourceURL, // Bundle should be present here when the package is linked into a framework. Bundle(for: BundleFinder.self).resourceURL, // For command-line tools. Bundle.main.bundleURL, ] for candidate in candidates { let bundlePath = candidate?.appendingPathComponent(bundleName + ".bundle") if let bundle = bundlePath.flatMap(Bundle.init(url:)) { return bundle } } fatalError("unable to find bundle named UniverseUI_UniverseUI") }() }
Lastly, our module target defines resources like so:
Code Block swift resources: [.process("Resources")]),
Is there any workaround so we don't trigger the fatalError when executing that code from a playground? Any check to know if Bundle.module is available?
Thank you