I have the following code:
@State private var isDataImported: Bool = false
init() {
NotificationCenter.default.addObserver(forName: .onDataImported, object: nil, queue: nil) { [self] notification in
print("Data has been imported...")
DispatchQueue.main.async {
self.isDataImported = true
print(self.isDataImported) // prints out false
}
}
}
I can debug and see that the notification is being fired. The line "Data has been imported" is printing. I want to update self.isDataImported property and then refresh my view.
if isDataImported {
ShowDataView()
} else {
ProgressView()
}
But the view ShowDataView never shows up since isDataImported is always false. What am I missing?