-
For example I have assets like this Is it possible to get color like Asset.PrimaryColor.color? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
SwiftGen won't do this for you (won't generate the code that does it). What you can do is, assuming both "styles" have the same set of colors, create a protocol such as: protocol Style {
static var primaryColor: ColorAsset { get }
…
} And conform both extension Asset.StyleA: Style {}
extension Asset.StyleB: Style {} Once all of that is set up, you'll probably have some style management service that will check some extension StyleService {
var activeStyle: Style {
if someCondition {
return Asset.StyleA
} else {
return Asset.StyleB
}
}
Something like that? Note that this isn't actually tested code, just something to push you into the right direction. All of the above should be possible without a custom template, but if you really want you could create your own template that does this 🤷 |
Beta Was this translation helpful? Give feedback.
SwiftGen won't do this for you (won't generate the code that does it).
What you can do is, assuming both "styles" have the same set of colors, create a protocol such as:
And conform both
StyleA
andStyleB
to your protocol like this:Once all of that is set up, you'll probably have some style management service that will check some
UserDefaults
and decide which style to return:Something like that? Note that …