如何使Xcode不能以奇怪的方式自动缩进Eureka表单代码?

时间:2017-08-14 13:28:46

标签: xcode auto-indent eureka-forms

当我使用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中的格式设置,但我什么也没找到。

然后我发现了与我正在寻找的最接近的东西 - 自动缩进。所以我取消选中}的复选框,如:

enter image description here

但是当我输入.onChange {然后按回车键时,会发生这种情况:

    let row = SwitchRow("") {
        row in
        }.onChange {

    }

怎么能让它不自动缩进呢?我想要上面提到的一种风格。

2 个答案:

答案 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)

虽然这并不妨碍Xcode每次格式化,但我认为这在大多数情况下都足够了。

解决方案是取消选中{的自动缩进:

enter image description here

显然,这些复选框控制的是“按下这些键时是否自动缩进”。

如果选中{框,当我输入{时,Xcode会自动缩进当前行,向右移动整个}.onChange{行。如果未选中,则不会发生这种情况。