I have a following class:
struct PriceFormatter {
@AppStorage(UserDefaultsKey.savedCurrency)
var savedCurrency: String?
let price: Float
init(price: Float) {
self.price = price
}
var formatted: String {
return "\(savedCurrency) \(price)"
}
}
And the following view:
struct PriceText: View {
let price: Float
var body: some View {
Text(PriceFormatter(price: self.price).formatted)
}
}
I want the view to get rerendered after savedCurrency from UserDefaults changes.
I made it work easily, when @AppStorage was a part of the view, but I'm not sure what to do in this case. I tried to use @ObservableObject with @Published or tried to make a Combine Publisher and subscribe to it but also had no success.