I have a SwiftUI view which depends on the state of a property of type Decimal. Changes in the decimal should trigger a view update, but doesn't for all changes of the decimal. If the decimal changes its sign (e.g. from 1 to -1) no view update is triggered. If the view depends on a string converted from the decimal the view updates just fine. Here is my code:
import SwiftUI
struct DecimalText: View {
var amount: Decimal
var body: some View {
Text(NSDecimalNumber(decimal: amount).stringValue)
}
}
struct MyTest: View {
@State var a: Decimal = 1
@State var b: Decimal = -1
var body: some View {
Text(NSDecimalNumber(decimal: a).stringValue)
DecimalText(amount: a)
Button("Click") {
if a == 1 {
a = b
} else {
a = 1
}
}
}
}
And here are two a visual examples. The first one changes just the sign of the decimal from 1 to -1 which does not trigger an update of the view depending on the decimal, but does for the view depending on the string. The second example shows that both views are updated correctly if not just the sign of the decimal changes.

