When I update the isDisabled
state variable in my view, it updates the .disabled
modifier of my text field as expected, but it then causes about 40 instances of the following error to appear in the console (with varying attribute numbers at the end):
=== AttributeGraph: cycle detected through attribute 200472 ===
And then it says: AttributeGraphError[59460:4808136] [SwiftUI] Modifying state during view update, this will cause undefined behavior.
Here is a minimal version of the code producing the error:
struct ContentView: View {
@State var isDisabled = false
@State var text = ""
var body: some View {
VStack {
TextField("", text: $text)
.textFieldStyle(.roundedBorder)
.disabled(isDisabled)
Button("Disable text field") { isDisabled = true }
}
}
}
How do I fix this error?