I am using ViewModel
class and want to setup observer if any changes into loginResponse
variable.
@objcMembers class ViewModel: NSObject {
var count = 300
@objc dynamic var loginResponse :String
override init() {
loginResponse = "1"
super.init()
setupTimer()
}
func setupTimer(){
_ = Timer.scheduledTimer(timeInterval: 1.0, target: self, selector:#selector(callTimer), userInfo: nil, repeats: true)
}
func callTimer(){
let minutes = String(count / 60)
let seconds = String(count % 60)
loginResponse = minutes + ":" + seconds
count = count - 1
}
}
View controller code:
override func viewDidLoad() {
super.viewDidLoad()
_ = viewModel.observe(\ViewModel.loginResponse) { (model, changes) in
print(changes)
}
}
I want to listen to any change into loginResponse
variable in my Viewcontroller but it's not getting the callback. What am I doing wrong here?