Created
August 25, 2017 10:39
-
-
Save bricklife/a279e9e6049d9e3c297dce249e6ca020 to your computer and use it in GitHub Desktop.
bind(to:) function for ReactiveSwift
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
import ReactiveSwift | |
import enum Result.NoError | |
extension BindingSource { | |
@discardableResult | |
func bind<P: BindingTargetProvider>(to provider: P) -> Disposable? where P.Value == Value, Error == NoError { | |
return provider <~ self | |
} | |
@discardableResult | |
func bind<P: BindingTargetProvider>(to provider: P) -> Disposable? where P.Value == Value?, Error == NoError { | |
return provider <~ self | |
} | |
} |
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
let label = UILabel() | |
let textProperty = MutableProperty("") | |
// Not good for me... | |
let disposable = label.reactive.text <~ textProperty | |
// Good! | |
let disposable = textProperty.bind(to: label.reactive.text) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment