Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

accentColor didn't work with Defaults #139

Closed
owenzhao opened this issue May 31, 2023 · 2 comments
Closed

accentColor didn't work with Defaults #139

owenzhao opened this issue May 31, 2023 · 2 comments

Comments

@owenzhao
Copy link

I set accent color to system orange in assets folder. And in code

static let traceColor = Defaults.Key<Color>("traceColor", default: Color.orange) // works
static let traceColor = Defaults.Key<Color>("traceColor", default: Color.accentColor) // doesn't work

when reset the default key,

Defaults.reset(.traceColor)

The accentColor set by reset is the system default blue instead my own setting orange. Any idea?

Defaults 7.2.0
Xcode 14.3.1 (14E300b)
iOS 16.5

@sindresorhus
Copy link
Owner

I don't think there's much we can do about this other than documenting the behavior. Color is not directly serializable, so the serialization works by first converting to UIColor/NSColor and then using the native color serialization.

As a workaround, you could store UIColor.tintColor and then just wrap it in Color() where you use it.

@owenzhao
Copy link
Author

static let traceColor = Defaults.Key<Color>("traceColor", default: Color(uiColor: .tintColor))

Suggested worked. Thank you and please add this to the document as a workaround.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants