Skip to content

Instantly share code, notes, and snippets.

@Sajjon
Created October 19, 2018 09:12
Show Gist options
  • Save Sajjon/94e7af9923b7eee9f74aacb787055a71 to your computer and use it in GitHub Desktop.
Save Sajjon/94e7af9923b7eee9f74aacb787055a71 to your computer and use it in GitHub Desktop.
Simple Settings View
import UIKit
import RxSwift
import RxCocoa
// MARK: - SettingsView
final class SettingsView: ScrollingStackView {
private lazy var signOutButton: UIButton = "Sign out"
// Two `UILabel`s grouped together
private lazy var appVersionLabels = LabelsView(
titleStyle: "App Version",
valueStyle: "🤷‍♀️",
stackViewStyle: UIStackView.Style(alignment: .center)
)
// Config type used to create a UIStackView conforming to `ExpressibleByArrayLiteral`
// initialized by UIViews as `arrangedSubviews`
lazy var stackViewStyle: UIStackView.Style = [
signOutButton,
appVersionLabels,
.spacer
]
}
extension SettingsView: ViewModelled {
typealias ViewModel = SettingsViewModel
// Forward user input from this View to the ViewModel
var inputFromView: ViewModel.Input {
return ViewModel.Input(
signOutTrigger: signOutButton.rx.tap.asDriver()
)
}
// Update this View with formatted data from the ViewModel
func populate(with viewModel: ViewModel.Output) -> [Disposable] {
// Populate `UILabel` in `LabelsView` holding value
return [
viewModel.appVersion.drive(appVersionLabels.rx.value)
]
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment