Connecting outlets is not interesting, let’s focus on ViewController.setupObserving. This method makes all UI controls “alive” by assigning properties / actions to them. See ViewController.swift.Let’s go for them one-by-one:

  1. We’re adding reactive extension weatherFeatures on WeatherView to bind an appropriate property from ViewModel. This gonna be implemented in ViewModel
  2. viewModel.isLoading should be implemented as SignalProducer<Bool, NoError>to bind to activity indicator
  3. isEnabled(for:) is a function returning SignalProducer. This is bound to isEnabled property of UISegmentedControl
  4. The same for title, but String, not Bool
  5. We’re creating a binding target for rightBarButtonItem and binding either the activity indicator or the refresh button, depending on the state
  6. We’re wrapping actions for left, right, reload, locate buttons into CocoaAction and assigning them to reactive.pressed property. This automatically handles click events and isEnabled state.
  7. We’re adding a custom handler for UISegmentedControl.controlEvents signal, because it has no built-in action expression

Implementations in ViewModel look like this.

Screen in IB

Screen in IB