asset-plugin

1.0.0

Structured asset & font generator for modern Swift projects.
xtro/assets-plugin

What's New

Initial release

2026-01-01T07:22:39Z

Structured Assets Generator Plugin
Type-safe access to assets and fonts for modern Swift projects.

Why

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.


What You Get

  • Deterministic, CI-friendly code generation
  • Folder-structure–driven Swift namespaces
  • Type-safe access to Image and Color
  • 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.


Configuration

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.

Minimal example

{
    "resourcesDir": "Resources",
    "outputDir": "Generated",
    "output": "Assets.swift",
    "name": "Assets",
    "access": "internal"
}

Usage

Images

// Resources/Assets.xcassets/Images/Icons/close.imageset
Image = Assets.Images.Icons.close

SwiftUI:

Image(Assets.Images.Icons.close)

Colors

// Resources/Assets.xcassets/Colors/Brand/primary.colorset
let color = Assets.Colors.Brand.primary

SwiftUI:

Text("Hello")
  .foregroundStyle(Assets.Colors.Brand.primary)

Fonts

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+

Installation

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.


Design Constraints

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.


Hacker News Compatibility Statement

  • No YAML
  • No scripts
  • No runtime reflection
  • No global registries
  • No code generation at app launch

Just SwiftPM doing its job.


Status

Actively used. Stable behavior. Minimal surface area.
Expect refinement, not reinvention.


License

MIT.
Fork it. Ship it. Improve it.
Please don’t turn it into a framework.

Description

  • Swift Tools 5.11.0
View More Packages from this Author

Dependencies

  • None
Last updated: Wed Jan 07 2026 22:10:33 GMT-1000 (Hawaii-Aleutian Standard Time)