2017-08-14 27 views
0

當我使用Eureka表單時,Xcode似乎想要以可能導致混淆的方式對其進行格式化。如何讓Xcode不會自動縮進Eureka以奇怪的方式形成代碼?

我將使用代碼塊的一個自述爲例:

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 {然後按Enter,出現這種情況:

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

    } 

怎樣才能使它無法自動縮進呢?我想要一個上面提到的樣式。

回答

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) 
}) 
0

雖然這並不妨礙Xcode中每次都從格式化,我想這足以在大多數情況下。

解決的辦法是取消自動縮進{

enter image description here

顯然,這些東西控制複選框是「是否自動縮進時,這些鍵被按下」。

如果選中{框,當我輸入{時,Xcode將自動縮進當前行,將整個}.onChange{行移到右側。如果沒有檢查,這不會發生。

相關問題