-
-
Notifications
You must be signed in to change notification settings - Fork 26
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement support for Codable
types
#92
Conversation
Codable
types. Close #72
Codable
types. Close #72Codable
types
} | ||
} | ||
|
||
/// :nodoc: | ||
extension UserDefaultsSerializable where Self: RawRepresentable, Self.RawValue: UserDefaultsSerializable { | ||
public var storedValue: RawValue.StoredValue { self.rawValue.storedValue } | ||
|
||
public init(storedValue: RawValue.StoredValue) { | ||
self = Self(rawValue: Self.RawValue(storedValue: storedValue))! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
An added benefit of this change is that the RawRepresentable
implementation no longer needs this force-unwrap
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks legit!
I guess a saving grace is one still has to mark the Codable type with UserDefaultsSerializable before Foil will accept it, so that's an opportunity to wonder if it's a good idea.
I see that SwiftUI.AppStorage doesn't afford any conveniences for Codable types. No idea why, maybe it's dissuasion or maybe e.g. it didn't fit as nicely with that interface.
Thanks for the quick review @nolanw! 🙌🏼 I added a few more commits if you want to take another quick look.
I think probably dissuasion. But curiously, it does not support raw value enums, which is frustrating. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I appreciate the note about compactMap use :)
thanks @nolanw ! 💯 |
Closes #72