Skip to content

Instantly share code, notes, and snippets.

@braker1nine
Created May 16, 2023 18:14
Show Gist options
  • Save braker1nine/a687fbb13a03edc1c483a1c15b739199 to your computer and use it in GitHub Desktop.
Save braker1nine/a687fbb13a03edc1c483a1c15b739199 to your computer and use it in GitHub Desktop.
ReactiveSwift Bindings
extension MutablePropertyProtocol {
var binding: Binding<Value> {
var binding: Binding<Value> = .init {
self.value
} set: { newValue in
self.value = newValue
}
self.signal.observeValues { value in
binding.update()
}
return binding
}
}
extension PropertyProtocol {
var binding: Binding<Value> {
var binding: Binding<Value> = .init {
self.value
} set: { _ in }
self.signal.observeValues { value in
binding.update()
}
return binding
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment