Last active
July 2, 2020 10:10
-
-
Save tonnylitao/b1c2f05753605b908cc2d725be685067 to your computer and use it in GitHub Desktop.
data flow to view mode with keypath
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let mapping = [\User.name: nameField, | |
\User.email: emailField, | |
\User.likeKiwi: likeKiwiSwitcher, | |
\User.travel: travelBtn, | |
\User.hiking: hikingBtn, | |
\User.reading: readingBtn] | |
func update(_ keypath: PartialKeyPath<User>, _ value: Any) { | |
model[keyPath: keypath] = value | |
mapping[keypath].value = value | |
} | |
... | |
update(\User.name, "Tonny") | |
update(\User.email, "[email protected]") | |
update(\User.likeKiwi, true) | |
update(\User.travel, false) | |
update(\User.hiking, true) | |
update(\User.reading, true) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment