Skip to content

Instantly share code, notes, and snippets.

@ncreated
Created August 11, 2017 15:24
Show Gist options
  • Save ncreated/929328a8f2cd180bab34310ca4d63142 to your computer and use it in GitHub Desktop.
Save ncreated/929328a8f2cd180bab34310ca4d63142 to your computer and use it in GitHub Desktop.
Medium blogpost snippet
import UIKit
import RxCocoa
import RxSwift
class SettingsViewController: UIViewController {
@IBOutlet weak var settingSwitch1: UISwitch!
@IBOutlet weak var settingSwitch2: UISwitch!
@IBOutlet weak var settingSwitch3: UISwitch!
@IBOutlet weak var settingSwitch4: UISwitch!
@IBOutlet weak var settingSwitch5: UISwitch!
@IBOutlet weak var settingSwitch6: UISwitch!
private let toggle1 = Toggle(storage: NetworkToggleStorage(value: false))
private let toggle2 = Toggle(storage: NetworkToggleStorage(value: true))
private let toggle3 = Toggle(storage: NetworkToggleStorage(value: false))
private let toggle4 = Toggle(storage: NetworkToggleStorage(value: true))
private let toggle5 = Toggle(storage: NetworkToggleStorage(value: false))
private let toggle6 = Toggle(storage: NetworkToggleStorage(value: true))
override func viewDidLoad() {
super.viewDidLoad()
setUp(settingSwitch: settingSwitch1, with: toggle1)
setUp(settingSwitch: settingSwitch2, with: toggle2)
setUp(settingSwitch: settingSwitch3, with: toggle3)
setUp(settingSwitch: settingSwitch4, with: toggle4)
setUp(settingSwitch: settingSwitch5, with: toggle5)
setUp(settingSwitch: settingSwitch6, with: toggle6)
}
private func setUp(settingSwitch: UISwitch, with toggle: Toggle) {
let (value, isBusy) = toggle.manage(change: settingSwitch.rx.isOn.changed.asObservable())
// ...
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment