Reputation: 4675
My Structure,
internal struct KeychainManager {
static private(set) var accessToken: String? = nil
}
My UI bind code,
override func viewDidLoad() {
super.viewDidLoad()
let observableToken = Observable.just(KeychainManager.accessToken)
observableToken
.debug()
.map { $0 == nil }
.bind(to: authenticateButton.rx.isEnabled)
.disposed(by: disposeBag)
}
When my app opens, authenticateButton
can be seen enabled, but when I make API call then after saving my token successfully in KeychainManager.accessToken
, authenticateButton
still remains enabled. Why?
What's going wrong here?
Any suggestions will be helpful.
Upvotes: 0
Views: 160
Reputation: 6018
. just
takes an argument and sends it as .next
and then send .completed
right after the .next
. It means that .just
called only once. But you need really observe every change of accessToken
value. Two ways to achieve that:
*Subject
. In this case, after accessToken
set you should manually call subject.onNext(accessToken)
(send event that accessToken
changed) and handle this subject
in your controller.Upvotes: 1