How to fix broken indention on copy/paste Xcode

Viewed 874

After upgrading xcode to v.11 my indention is off when I copy/paste code. The example below shows how it looks when I copy a code. Does anybody know how to fix this?

public func configure(_ view: WithdrawelView) {
        view.paySumLabel.text = self.pay
        view.expensesSumLabel.text = self.expenses
        view.refundSumLabel.text = self.refund
        view.taxLastYearSumLabel.text = self.taxLastYear
        view.futureWithdrawelSumLabel.text = self.futureWithdrawel
        view.balanceSumLabel.text = self.balance
    }
public func configure(_ view: WithdrawelView) {
           view.paySumLabel.text = self.pay
           view.expensesSumLabel.text = self.expenses
           view.refundSumLabel.text = self.refund
           view.taxLastYearSumLabel.text = self.taxLastYear
           view.futureWithdrawelSumLabel.text = self.futureWithdrawel
           view.balanceSumLabel.text = self.balance
       }
3 Answers

Go to Preferences -> Text Editing -> Indentation and check "Re-indent on paste"

Select the code in question and use ctrl+i to auto indent the selected code.

I had a similar problem where pasted code would mysteriously be indented 3 spaces instead of 4, making it subtly "wrong" and causing anal-retentive me to waste time re-indenting.

Re-indent on paste didn't work for me, it just removes indentation entirely and pastes the entire block at the same indentation, regardless of brackets/previous indentation.

What did work for me is switching to tabs from spaces in Preferences->Text Editing->Indentation, and turning off Re-indent. Now everything maintains proper indentation, but is pasted one level too deep which is much easier to fix (select block, command-[).

Related