Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

A SwiftGen SwiftUI template for Xcode asset catalog colors and images

Notifications You must be signed in to change notification settings

sebj/SwiftGen-SwiftUI-xcassets

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 

Repository files navigation

A SwiftGen SwiftUI template for Asset Catalogs

This template is a fork of SwiftGen's bundled xcassets/swift4.stencil template, to generate SwiftUI supporting type-safe code for colors and images in an Xcode asset catalog (*.xcassets).

It supports most of the same options, and produces mostly the same output.

♻️ Changed:

  • name property for assets is fileprivate, instead of using accessModifier option value (internal by default)

🔥 Removed:

  • Compiler checks for platform, as SwiftUI supports all Apple platforms
  • Generation for data assets (including the dataType option parameter), as this template focuses on SwiftUI support
  • Option parameters colorAliasName, and imageAliasName, as SwiftUI uses Color and Image types on all platforms

Usage Example

// You can create new images with the convenience constructor like this:
let bananaImage = Image(Asset.Exotic.banana)
let privateImage = Image(Asset.private)

// Or as an alternative, you can refer to an enum instance and call .image on it:
let sameBananaImage = Asset.Exotic.banana.image
let samePrivateImage = Asset.private.image

// You can create colors by referring to the enum instance and calling `.color` on it:
let primaryColor = Asset.Theme.primary.color
let backgroundColor = Asset.Theme.background.color

// Or as an alternative, you can use the convenience constructor like this:
let samePrimaryColor = Color(asset: Asset.Theme.primary)
let sameBackgroundColor = Color(asset: Asset.Theme.background)

Further documentation

See SwiftGen's documentation for full usage and insallation information for the tool itself.

See SwiftGen's documentation for the xcassets/swift4.stencil template for information on the options and generated code available.

About

A SwiftGen SwiftUI template for Xcode asset catalog colors and images

Topics

Resources

Stars

Watchers

Forks