Skip to content

Instantly share code, notes, and snippets.

@vince19972
Created September 9, 2019 23:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vince19972/d0b132129a2f57b3588bfb942dabfe63 to your computer and use it in GitHub Desktop.
Save vince19972/d0b132129a2f57b3588bfb942dabfe63 to your computer and use it in GitHub Desktop.
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