amzn / style-dictionary

A build system for creating cross-platform styles.
https://styledictionary.com
Apache License 2.0
3.92k stars 555 forks source link

Design tokens as Swift structures #933

Open ssayfulin69 opened 1 year ago

ssayfulin69 commented 1 year ago

Let's say I have my tokens like this:

[category.foo]
attribute1.value = 1
attribute2.value = 2
attribute3.value = 3

[category.bar]
attribute1.value = 1
attribute2.value = 2
attribute3.value = 3

Can I transform it to get the result below using only provided tools?

struct Category {
    let attribute1: CGFLoat
    let attribute2: CGFLoat
    let attribute3 CGFLoat

  init(
    attribute1: CGFLoat,
    attribute2: CGFLoat,
    attribute3 CGFLoat
  ) {
    self.attribute1 = attribute1
    self.attribute2 = attribute2
    self.attribute3 = attribute3
  }
}

extension Category {
  static let foo = Category(...)
  static let bar = Category(...)
}
nahiyankhan commented 1 year ago

To my knowledge no. That seems like you would need a custom formatter. We went the custom route for our UIKit / SwiftUI / Kotlin outputs, types and wrappers.