-
Notifications
You must be signed in to change notification settings - Fork 0
Introduce new @UserDefaultOverride
property wrapper for better UI testing support
#8
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
Conversation
@UserDefaultOverride
property wrapper to make UI Testing configuration easier@UserDefaultOverride
property wrapper for better UI testing support
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.
🚀🚀🚀 Really cool, excited to use it!
980f59d
to
756f916
Compare
…ore predictably based on input order
…f launchArguments
…ers to align better with @AppStorage and @userdefault
…y to seperate usage of Mirror and allow for possible customisation
9aca796
to
4c64df2
Compare
I just pushed some slight tweaks in the last two commits - https://github.com/cookpad/swift-user-defaults/pull/8/files/f9e9c3e9a6b03a84e19c224edf26036bbb7bfac1..4c64df2a637f90dea5b1d221addb0230236e571f They change the |
Background
When prototyping the integration within a real iOS app, I found using
UserDefaults.ValueContainer()
somewhat repetitive.We defined a
Configuration
type that held a series of properties that related to UserDefaults, but to map that into the value container resulted in a lot of repetitive code:It would be great to avoid this somehow.
Description
In this PR, I'm proposing two new types:
LaunchArgumentEncodable
protocol@UserDefaultOverride
property wrapperThey work in conjunction with each other and build on top of the functionality already provided by
UserDefaults.ValueContainer
.LaunchArgumentEncodable
is pretty simple:But it is somewhat magic. The
encodeLaunchArguments()
method will use Swift's reflection apis to find and iterate all of the@UserDefaultOverride
properties defined on the type. It'll then collect the keys and values and pass them into aValueContainer
that is then used to produce the array of launch arguments.In use, it looks something like this:
In addition to this change, I updated
UserDefaults.ValueContainer
so thatlaunchArguments
returns key value pairs ordered based on when they were inserted. This helps us predictably test the output.