Based on this question, it’s not the way to go but how do I go about handling this so I can update UI elements when said property is update.
This would easily be achieved in SwiftUI using @Published
var exchangeRate: Double = 1.0 {
willSet {
guard let doubleFormattedValue = Double.format(newValue, numberStyle: .decimal, decimalPlaces: 6) else { return }
DispatchQueue.main.async {
self.rateLabel.text = String(doubleFormattedValue) + " " + self.fromCurrencyTextField.currency.rawValue
}
}
}
2
Answers
Following the suggestion of @Paulw11 and this tutorial, I was able to implement the following:
ViewModel shouldn’t have any inforamtion about the View you can use binding with change handler and escaping, this solution is without combine or rxswift or async await etc.
such as:
in your view you can have:
To me MVVM does not depend on UIView or SwiftUI or Snappkit, you can use MVVM with every UI that you want. this is a general Architecture.