Showing Recent Messages Swift package target 'Core' is linked as a static library by 'AppCommoms' and 'Core', but cannot be built dynamically because there is a package product with the same name.
Swift package target 'Core' is linked as a static library by 'Onboarding' and 'Core', but cannot be built dynamically because there is a package product with the same name.
Swift package target 'Core' is linked as a static library by 'AppSDK' and 'Core', but cannot be built dynamically because there is a package product with the same name.
classAppCommomsBundle { staticvar module: Bundle= { // Bundle name should be like this "ProductName_TargetName" let bundleName ="AppCommoms_AppCommoms" 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, // SwiftUI Preview Bundle(for: BundleFinder.self).resourceURL?.deletingLastPathComponent().deletingLastPathComponent(), // For command-line tools. Bundle.main.bundleURL ] +Bundle.allBundles.map { $0.bundleURL } for candidate in candidates { let bundlePath = candidate?.appendingPathComponent(bundleName +".bundle") iflet bundle = bundlePath.flatMap(Bundle.init(url:)) { return bundle } } returnBundle(for: BundleFinder.self) // fatalError("unable to find bundle named \(bundleName)") }() }
使用Bundle.module
还有一种更简单的方案就是用Apple推荐的Bundle.module,也是Rswift使用的public let R = _R(bundle: Bundle.module)。
Access a resource in codein page link Always use Bundle.module when you access resources. A package shouldn’t make assumptions about the exact location of a resource.
import class Foundation.Bundle import class Foundation.ProcessInfo import struct Foundation.URL
privateclassBundleFinder {}
extensionFoundation.Bundle { /// Returns the resource bundle associated with the current Swift module. staticlet module: Bundle= { let bundleName ="Onboarding_Onboarding"
let overrides: [URL] #ifDEBUG // 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. ifletoverride=ProcessInfo.processInfo.environment["PACKAGE_RESOURCE_BUNDLE_PATH"] ??ProcessInfo.processInfo.environment["PACKAGE_RESOURCE_BUNDLE_URL"] { overrides = [URL(fileURLWithPath: override)] } else { overrides = [] } #else overrides = [] #endif
let candidates = overrides + [ // 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") iflet bundle = bundlePath.flatMap(Bundle.init(url:)) { return bundle } } fatalError("unable to find bundle named Onboarding_Onboarding") }() }