我怎样才能使 Xcode 不以奇怪的方式自动缩进 Eureka 表单代码?
How can I make Xcode not auto indent Eureka forms code in a weird way?
当我使用 Eureka 表单时,Xcode 似乎喜欢以一种可能导致混淆的方式格式化它。
我将使用 README 中的代码块之一作为示例:
let row = SwitchRow("SwitchRow") { row in // initializer
row.title = "The title"
}.onChange { row in
row.title = (row.value ?? false) ? "The title expands when on" : "The title"
row.updateCell()
}.cellSetup { cell, row in
cell.backgroundColor = .lightGray
}.cellUpdate { cell, row in
cell.textLabel?.font = .italicSystemFont(ofSize: 18.0)
}
这真的让我的强迫症消失了。最后一个 }
与所有其他的不一致感觉很烦人。
我想这样格式化:
let row = SwitchRow("SwitchRow") { row in // initializer
row.title = "The title"
}.onChange { row in
row.title = (row.value ?? false) ? "The title expands when on" : "The title"
row.updateCell()
}.cellSetup { cell, row in
cell.backgroundColor = .lightGray
}.cellUpdate { cell, row in
cell.textLabel?.font = .italicSystemFont(ofSize: 18.0)
}
或者这个:
let row = SwitchRow("SwitchRow") { row in // initializer
row.title = "The title"
}.onChange { row in
row.title = (row.value ?? false) ? "The title expands when on" : "The title"
row.updateCell()
}.cellSetup { cell, row in
cell.backgroundColor = .lightGray
}.cellUpdate { cell, row in
cell.textLabel?.font = .italicSystemFont(ofSize: 18.0)
}
所以我去了 Xcode 的首选项面板并寻找自定义缩进之类的东西。我以为会有类似于 IntelliJ 中的格式设置的东西,但我什么也没找到。
然后我找到了最接近我要找的东西 - 自动缩进。所以我取消选中 }
的复选框,例如:
但是当我键入 .onChange {
然后按回车键时,会发生这种情况:
let row = SwitchRow("") {
row in
}.onChange {
}
如何让它不自动缩进?我想要上面提到的一种款式。
如果您愿意使用非尾随语法,即使用额外的括号(诚然这会使代码有点膨胀),自动缩进应该可以正常工作。
您的示例代码被格式化为:
let row = SwitchRow("SwitchRow", { row in // initializer
row.title = "The title"
}).onChange({ row in
row.title = (row.value ?? false) ? "The title expands when on" : "The title"
row.updateCell()
}).cellSetup({ cell, row in
cell.backgroundColor = .lightGray
}).cellUpdate({ cell, row in
cell.textLabel?.font = .italicSystemFont(ofSize: 18.0)
})
虽然这不会阻止Xcode每次格式化它,但我认为这在大多数情况下就足够了。
解决方案是取消选中 {
:
的自动缩进
显然那些复选框控制的是 "whether to auto indent when these keys are pressed"。
如果选中 {
框,Xcode 将在我键入 {
时自动缩进当前行,将整个 }.onChange{
行向右移动。如果未选中,则不会发生这种情况。
当我使用 Eureka 表单时,Xcode 似乎喜欢以一种可能导致混淆的方式格式化它。
我将使用 README 中的代码块之一作为示例:
let row = SwitchRow("SwitchRow") { row in // initializer
row.title = "The title"
}.onChange { row in
row.title = (row.value ?? false) ? "The title expands when on" : "The title"
row.updateCell()
}.cellSetup { cell, row in
cell.backgroundColor = .lightGray
}.cellUpdate { cell, row in
cell.textLabel?.font = .italicSystemFont(ofSize: 18.0)
}
这真的让我的强迫症消失了。最后一个 }
与所有其他的不一致感觉很烦人。
我想这样格式化:
let row = SwitchRow("SwitchRow") { row in // initializer
row.title = "The title"
}.onChange { row in
row.title = (row.value ?? false) ? "The title expands when on" : "The title"
row.updateCell()
}.cellSetup { cell, row in
cell.backgroundColor = .lightGray
}.cellUpdate { cell, row in
cell.textLabel?.font = .italicSystemFont(ofSize: 18.0)
}
或者这个:
let row = SwitchRow("SwitchRow") { row in // initializer
row.title = "The title"
}.onChange { row in
row.title = (row.value ?? false) ? "The title expands when on" : "The title"
row.updateCell()
}.cellSetup { cell, row in
cell.backgroundColor = .lightGray
}.cellUpdate { cell, row in
cell.textLabel?.font = .italicSystemFont(ofSize: 18.0)
}
所以我去了 Xcode 的首选项面板并寻找自定义缩进之类的东西。我以为会有类似于 IntelliJ 中的格式设置的东西,但我什么也没找到。
然后我找到了最接近我要找的东西 - 自动缩进。所以我取消选中 }
的复选框,例如:
但是当我键入 .onChange {
然后按回车键时,会发生这种情况:
let row = SwitchRow("") {
row in
}.onChange {
}
如何让它不自动缩进?我想要上面提到的一种款式。
如果您愿意使用非尾随语法,即使用额外的括号(诚然这会使代码有点膨胀),自动缩进应该可以正常工作。
您的示例代码被格式化为:
let row = SwitchRow("SwitchRow", { row in // initializer
row.title = "The title"
}).onChange({ row in
row.title = (row.value ?? false) ? "The title expands when on" : "The title"
row.updateCell()
}).cellSetup({ cell, row in
cell.backgroundColor = .lightGray
}).cellUpdate({ cell, row in
cell.textLabel?.font = .italicSystemFont(ofSize: 18.0)
})
虽然这不会阻止Xcode每次格式化它,但我认为这在大多数情况下就足够了。
解决方案是取消选中 {
:
显然那些复选框控制的是 "whether to auto indent when these keys are pressed"。
如果选中 {
框,Xcode 将在我键入 {
时自动缩进当前行,将整个 }.onChange{
行向右移动。如果未选中,则不会发生这种情况。