Last active
March 26, 2024 19:02
-
-
Save antonyalkmim/1a2a3b42906ee077975c0589a02735f5 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
struct MyComponent: View { | |
var textColor: Color = .black | |
var textSize: CGFloat = 12 | |
} | |
extension MyComponent { | |
func set<V>(_ keypath: WritableKeyPath<Self, V>, to value: V) -> Self { | |
var copy = self | |
copy[keyPath: keypath] = value | |
return copy | |
} | |
} | |
MyComponent() | |
.set(\.textColor, .red) | |
.set(\.textSize, 22) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment