当我更新isDisabled视图中的状态变量时,它会.disabled按预期更新文本字段的修饰符,但随后会导致控制台中出现大约 40 个以下错误实例(末尾具有不同的属性编号):
=== AttributeGraph: cycle detected through attribute 200472 ===
然后它说:AttributeGraphError[59460:4808136] [SwiftUI] Modifying state during view update, this will cause undefined behavior.
这是产生错误的代码的最小版本:
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 }
}
}
}
Run Code Online (Sandbox Code Playgroud)
我该如何修复这个错误?
我在 Visual Studio Code 中安装了Red Hat 扩展的 Java(TM) 语言支持。除其他功能外,此扩展还可以自动格式化 java 代码。我已将其设置为每次保存文件时都执行此操作。
它似乎将最大行长度设置为 120 个字符,但我想将其设置为 80 个字符。我一直在到处寻找,但不知道在哪里可以找到相关的设置。
是否可以将格式化程序设置为不同的最大行长度?如果是这样,怎么办?