当我使用Eureka表格时,Xcode似乎想以一种可能引起混淆的方式对其进行格式化。
我将使用自述文件中的一个代码块作为示例:
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 {
}
怎么能让它不自动缩进呢?我想要上面提到的一种风格。
答案 0 :(得分: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)
})
答案 1 :(得分:0)