Skip to content

Instantly share code, notes, and snippets.

@PaulTaykalo
Created July 25, 2016 16:31
Show Gist options
  • Select an option

  • Save PaulTaykalo/b76fe251f4babed8591a1ff5d97a0cdd to your computer and use it in GitHub Desktop.

Select an option

Save PaulTaykalo/b76fe251f4babed8591a1ff5d97a0cdd to your computer and use it in GitHub Desktop.
Example selector/method binding
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