Skip to content

Can I get theme color #993

Answered by djbe
brian8219 asked this question in Q&A
Discussion options

You must be logged in to vote

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 StyleA and StyleB to your protocol like this:

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 UserDefaults and decide which style to return:

extension StyleService {
  var activeStyle: Style {
    if someCondition {
      return Asset.StyleA
    } else {
      return Asset.StyleB
    }
  }

Something like that? Note that …

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by brian8219
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants