Skip to content

Instantly share code, notes, and snippets.

@antonyalkmim
Last active March 26, 2024 19:02
Show Gist options
  • Save antonyalkmim/1a2a3b42906ee077975c0589a02735f5 to your computer and use it in GitHub Desktop.
Save antonyalkmim/1a2a3b42906ee077975c0589a02735f5 to your computer and use it in GitHub Desktop.
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