SwiftUI, Swift 5.2, Xcode 11.4
I'm trying to observe changes in a singleton, but I'm not always getting my SwiftUI view refreshed:
final class Patient: ObservableObject {
static var shared: Patient
@Published var medicalData: MedicalData
init { ... }
final class MedicalData {
var allergies: String
var ...
init { ... }
}
}
So, in my SwiftUI view:
struct ContentView: View {
@ObservedObject var patient: Patient = Patient.shared
var body: some view { ... }
}
If any object replaces the medical data, the publisher will inform my SwiftUI correctly:
patient.medicalData = NEW_MEDICAL_DATA --> OK! View refreshed
But if any object changes a value IN current medical data, the SwiftUI View is not refreshed:
patient.medicalData.allergies = "Alcanfor" --> NOT PUBLISHED
Does anyone knows how to accomplish this? Thank you in advance.