Unfortunately, I have the same issue in Version 14.0 (14A309) (release version).
I've thought out another workaround. It may not be acceptable for some scenarios but in other it may be bearable. Below is the example of 2 ObservableObject classes --> Object1 produces the error, Object2 does not.
class Object1: ObservableObject {
@Published var title = ""
func setTitle(to newTitle: String) {
title = newTitle // this causes the error in question ("Publishing changes from within view updates is not allowed, this will cause undefined behavior.")
}
}
class Object2: ObservableObject {
@Published var title = ""
func setTitle(to newTitle: String) {
DispatchQueue.main.asyncAfter(deadline: .now() + 0.1) { // performing the change later on removes the error because obviously it is not "within view updates"
self.title = newTitle
}
}
}
Topic:
UI Frameworks
SubTopic:
SwiftUI
Tags: