Structured Assets Generator Plugin
Type-safe access to assets and fonts for modern Swift projects.
A focused Swift Package Manager plugin that generates a structured, strongly-typed interface for your asset catalogs and bundled resources.
This plugin removes stringly-typed asset access and replaces it with a predictable, compiler-checked Swift API that mirrors your resource structure.
Motivation: Asset catalogs (.xcassets) and bundled fonts are first-class citizens in modern Apple platforms — yet accessing them safely still relies on fragile string literals. This plugin closes that gap by generating a clean, hierarchical Swift API directly from your Resources folder.
Assets are static.
Swift’s type system is strict.
Typos should not ship.
This Swift Package Manager plugin generates a hierarchical, namespaced, type-safe Swift API for images, colors, and fonts.
✅ No runtime lookup tables
✅ No reflection
✅ No hand-written enums
If it builds, the asset exists.
- Deterministic, CI-friendly code generation
- Folder-structure–driven Swift namespaces
- Type-safe access to
ImageandColor - SwiftUI-first API
- Font helpers generated from bundled fonts
- Works in app targets and Swift packages
- Zero runtime cost
Predictable input. Boring output. Maximum safety.
Place a configuration file named AssetsGeneratorConfig.json at the root of your package (next to Package.swift).
The plugin discovers this file automatically during builds.
{
"resourcesDir": "Resources",
"outputDir": "Generated",
"output": "Assets.swift",
"name": "Assets",
"access": "internal"
}// Resources/Assets.xcassets/Images/Icons/close.imageset
Image = Assets.Images.Icons.closeSwiftUI:
Image(Assets.Images.Icons.close)// Resources/Assets.xcassets/Colors/Brand/primary.colorset
let color = Assets.Colors.Brand.primarySwiftUI:
Text("Hello")
.foregroundStyle(Assets.Colors.Brand.primary)Bundled fonts are discovered automatically and exposed through generated helpers:
SwiftUI:
// Resources/Font/Inter-bold.otf
Text("Hello")
.font(Assets.Fonts.Inter.regular(size: 16))
Text("Hello")
.font(Assets.Fonts.Inter.regular(fixedSize: 16)) // iOS14+
Text("Hello")
.font(Assets.Fonts.Inter.regular(size: 16, relativeTo: .title)) // iOS14+Add the dependency:
.package(
url: "https://github.com/your-org/asset-generator-plugin.git",
from: "1.0.0"
)Attach the plugin to the target that owns the resources:
.target(
name: "AppCore",
resources: [
.process("Resources")
],
plugins: [
.plugin(
name: "AssetPlugin",
package: "asset-generator-plugin"
)
]
)Build the project.
Assets.swift is generated automatically.
This project is intentionally opinionated:
- Structure over configuration
- Compile-time safety over flexibility
- Generated code should be boring
- Folder layout is the API
It does not attempt to abstract Apple’s asset system. It embraces it.
- No YAML
- No scripts
- No runtime reflection
- No global registries
- No code generation at app launch
Just SwiftPM doing its job.
Actively used. Stable behavior. Minimal surface area.
Expect refinement, not reinvention.
MIT.
Fork it. Ship it. Improve it.
Please don’t turn it into a framework.
