Created
October 19, 2020 21:03
-
-
Save 0111b/a0dbc1e61529a3b4dd2820b921290100 to your computer and use it in GitHub Desktop.
This file contains 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
/// Adds a helper function to mutate a properties and help implement _Builder_ pattern | |
protocol Buildable { } | |
extension Buildable { | |
/// Mutates a property of the instance | |
/// | |
/// - Parameter keyPath: `WritableKeyPath` to the instance property to be modified | |
/// - Parameter value: value to overwrite the instance property | |
func mutating<T>(keyPath: WritableKeyPath<Self, T>, value: T) -> Self { | |
var newSelf = self | |
newSelf[keyPath: keyPath] = value | |
return newSelf | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment