Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Demo code of extending color and font in SwiftUI
struct TokenColor {
// --snip--
// see here for more: https://gist.github.com/vince19972/70eee7d66735739aa31567efd7a0a475
}
struct TokenTypography {
// --snip--
// see here for more: https://gist.github.com/vince19972/8ff8635bdb7bfdf54b85ab711b55f634l
}
// extend from native `Color` and `Font` struct
extension Color {
static let Token = TokenColor()
}
extension Font {
static let Typography = TokenTypography()
}
// use the tokens
struct ContentView: View {
Text("Demo of extension")
.font(Font.Typography.mainFont)
.foregroundColor(Color.Token.textTheme)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.