Created
July 25, 2016 16:31
-
-
Save PaulTaykalo/b76fe251f4babed8591a1ff5d97a0cdd to your computer and use it in GitHub Desktop.
Example selector/method binding
This file contains hidden or 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
| public func <~ <Destination, Source: SignalProducerType where Source.Value == Destination>(destinationSelector: (Destination) -> (), sourceProducer: Source) -> Disposable { | |
| return sourceProducer.startWithNext(destinationSelector) | |
| } | |
| // Without binding... | |
| viewModel.deliveryTime.producer | |
| .map { ($0, UIControlState.Normal) } | |
| .takeUntil(rac_willDeallocSignalProducer()) | |
| .startWithNext(deliveryTimeButton.setTitle) | |
| // With binding | |
| deliveryTimeButton.setTitle <~ | |
| viewModel.deliveryTime.producer | |
| .map { ($0, UIControlState.Normal) } | |
| .takeUntil(rac_willDeallocSignalProducer()) | |
| #### | |
| // Last one probably will lead to reference cycle in some cases, but | |
| // It's a bit readable in terms that you know what you're doing by reading first line of code | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment