Resources are from within the same module
So Bundle.
Can it be referenced from other target modules in the first place?
For example, let's consider a situation where FeatureB references an image resource from FeatureA.
Bundle.moduleis a module-specific bundle that Xcode automatically provides when you place Asset Catalog in a target. Therefore, if you remove Assets catalog from the tonga email address target, an error will occur saying "Module? There is no such bundle."
Let's also look at what happens if we move it to a different target, FeatureB.
An error also occurred in this case. ↑
Image resources placed in other targets cannot be referenced directly.
(Note: It is possible to expand it in memory once, import FeatureB, and obtain it as UIImage data.)
So, when XCAssets are placed in the FeatureA target, Bundle.modulewhat is the content that is automatically generated there?
Let's take a look.
In the case of the FeatureA target, it looks like this:
import class Foundation.Bundle
import class Foundation.ProcessInfo
import struct Foundation.URL
private class BundleFinder {}
extension Foundation.Bundle {
/// Returns the resource bundle associated with the current Swift module.
static let module : Bundle = {
let bundleName = "MyLibrary_FeatureA"
let overrides : [ URL ]
#if DEBUG
// The 'PACKAGE_RESOURCE_BUNDLE_PATH' name is preferred since the expected value is a path. The
// check for 'PACKAGE_RESOURCE_BUNDLE_URL' will be removed when all clients have switched over.
// This removal is tracked by rdar://107766372.
if let override = ProcessInfo.processInfo.environment[ "PACKAGE_RESOURCE_BUNDLE_PATH" ]
?? ProcessInfo.processInfo.environment[ "PACKAGE_RESOURCE_BUNDLE_URL" ] {
overrides = [URL(fileURLWithPath : override )]
} else {
modulewhat exactly is this?
-
- Posts: 58
- Joined: Tue Jan 07, 2025 5:03 am