This file contains 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
var title: String | |
var titleLabel: UILabel |
This file contains 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
var title: String { | |
didSet { | |
titleLabel.text = title | |
} | |
} |
This file contains 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
let disposeBag = DisposeBag() | |
let publishSubject = PublishSubject<String>() | |
//subscribe for changes | |
publishSubject | |
.subscribe(onNext: { title in | |
titleLabel.text = title | |
}) | |
.disposed(by: disposeBag) |
This file contains 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
class ProfileManager { | |
static let shared = ProfileManager() | |
let usernameObservable: Observable<String> | |
private let usernameSubject: BehaviorSubject<String> | |
private var username: String { | |
didSet { | |
usernameSubject.onNext(username) | |
} |
This file contains 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
RAC(self, titleLabel.text) = RACObserve(self, title); |
This file contains 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
@objc dynamic var titleKVO: String = "" | |
var titleObserver: Observable<String> { | |
return rx.observe(String.self, "titleKVO", options: .new) //using an Rx wrapper for KVO we can monitor new values of | |
} | |
let disposeBag = DisposeBag() | |
titleObserver | |
.subscribe(onNext: { title in | |
titleLabel.text = title |
This file contains 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
import UIKit | |
class ViewController: UIViewController { | |
@IBOutlet weak var loginTextField: UITextField? | |
@IBOutlet weak var passwordTextField: UITextField? | |
@IBOutlet weak var loginButton: UIButton? | |
override func viewDidLoad() { | |
super.viewDidLoad() |
This file contains 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
override func viewDidLoad() { | |
super.viewDidLoad() | |
loginButton?.isEnabled = false | |
guard let loginTextField = loginTextField, | |
let passwordTextField = passwordTextField, | |
let loginButton = loginButton else { | |
return | |
} |
This file contains 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
class ViewController: UIViewController { | |
@IBOutlet weak var loginTextField: UITextField? | |
@IBOutlet weak var passwordTextField: UITextField? | |
@IBOutlet weak var loginButton: UIButton? | |
private let disposeBag = DisposeBag() | |
private let viewModel = ViewModel() | |
override func viewDidLoad() { |
This file contains 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
@Published var title: String = "" | |
//And then you can change the variable itself: | |
title = "Bob" | |
//And also to track its changes: | |
let titleSubscription = $title.sink { | |
print("new title is '\($0)'") | |
} |
OlderNewer