Export ImageResource and ColorResource symbols generated from .xcassets so they can be used outside the defining Swift module. This is especially useful in modularized apps using Swift Package Manager, where Xcode generates these symbols as internal by default.
- Xcode automatically generates
ImageResourceandColorResourcesymbols for assets in.xcassets, but marks them asinternalwithin the Swift module that defines them. - In modularized projects (especially SPM-based), you often need to reference shared assets from other modules without exposing the whole asset catalog or duplicating names.
- This package provides a simple way to re-expose those generated symbols as
publicorpackageso they can be imported and used by other modules safely and ergonomically.
- Maps your xcassets namespaces and re-exports the generated symbols.
- Supports adding your own additional enum namespaces to group assets logically.
- Lets you choose the desired visibility:
publicorpackage. - Works seamlessly with:
- UIKit/AppKit:
UIImage,UIColor,NSImage,NSColor - SwiftUI:
Image,Color
- UIKit/AppKit:
- iOS, iPadOS:
UIImage,UIColor, SwiftUIImage,Color - macOS:
NSImage,NSColor, SwiftUIImage,Color - tvOS, watchOS:
UIImage/UIColorwhere applicable, SwiftUIImage/Color
Use the exported ImageResource and ColorResource values directly with the initializers provided by Apple frameworks.
Package.swift:
// Add the dependency
.package(url: "https://github.com/quentinfasquel/SwiftPackageAssets", from: "1.0.0"),
// Add to a target
.target(
name: "FeatureUI",
dependencies: [
.product(name: "PackageAssets", package: "SwiftPackageAssets")
]
)Assets.swift:
import PackageAssets
extension Assets.ImageResource {
#ImageResource {
.carrotFill
}
}
extension Assets.ColorResource {
#ColorResource(.public) {
.carrotOrange;
.Vegetable.carrot;
}
}