< How to fix “Modifying state during view update, this will cause undefined behavior” | How to fix “Fatal error: No ObservableObject of type SomeType found” > |
Updated for Xcode 12.5
This is a particularly confusing problem, and it occurs because SwiftUI relies heavily on opaque return types. The problem happens because of code like this:
struct ContentView: View {
var body: View {
Text("SwiftUI")
}
}
It feels like such a tiny thing, but the body
property is declared as returning View
rather than some View
. The difference is small but important – you can find out more about it in my article How to use opaque return types in Swift 5.1.
So, to fix the problem use this instead:
struct ContentView: View {
var body: some View {
Text("SwiftUI")
}
}
SPONSORED ViRE offers discoverable way of working with regex. It provides really readable regex experience, code complete & cheat sheet, unit tests, powerful replace system, step-by-step search & replace, regex visual scheme, regex history & playground. ViRE is available on Mac & iPad.
Sponsor Hacking with Swift and reach the world's largest Swift community!
Link copied to your pasteboard.