Question: How to make Xcode put starting brace on new line in Swift?


How to make Xcode put starting brace on new line in Swift?

Answers 1
Added at 2016-12-10 15:12

I have noticed that the coding style in Swift appears to be to put braces on the same line as a method signature or if statement etc. Without getting into a debate about which is right or wrong, my aim is simply tom get Xcode to put the braces on a new line when it does its auto completion and for the new file templates.

I've tried the advice here and it doesn't work:

I'm using Xcode 8.1 on Sierra.

Has anyone else been able to get this to work?

Thanks, Alan

nr: #1 dodano: 2016-12-10 19:12

You can use below methods in conjusction to acomplish this task.

Snippet Edit

Snippet Edit is a small program that is used to edit the Xcode's standard code snippets. We have to do this way because there is no direct way to change the code style in Xcode settings and XCCodeSenseFormattingOptions is not supported since Xcode 4

You can follow below screenshot for reference. Remember to restart Xcode once you are done with editing.

enter image description here

ClangFormat and Uncrustify

Above method will only change the default statement templetes and not the inbuilt methods formatting. (i.e autofilled viewDidLoad() method will still have the braces in the same line.) For this you should consider using these plugins. They have options to save the file with specified format.

Source Show
◀ Wstecz