Automatic formatting of Swift code

There's a weird behaviour in Xcode when writing Swift code.

Try to write this code for example:


var fullName: Bool
{
    get
    {
        return firstName + " " + lastName
    }
    set
    {
        splitFullName(fullName);
    }
}


Now what really happens is this:

var fullName: Bool
    {
    get
    {
        return firstName + " " + lastName
    }
    set
    {
        splitFullName(fullName);
    }
}


That weird indentation is something that Xcode strongly insists on. And I know that although Apple developer seem to think that brackets on the same line is better for some reason, there's no way in **** they think that that indentation is correct!

If you think it's a bug, file a bug report. https://developer.apple.com/bug-reporting/

Going to the "Text Editing" tab in Xcode prefences and turning off auto-indentation for the opening brace "{" seems to help, although there is still some occasional weirdness when using a balanced style.

Apple has stopped responding to bug reports a long time ago. But in the WWDC they ask us to come talk to them in the forums all the time.

Yeah it still behaves weird.

It's clearly a bug, because it's inconsistent, and depends on what comes before. I've found that most of the old indentation bugs in {-at-the-end-of-the-previous-line style have been fixed, but there are plenty left in the {-on-a-new-line style. Presumably because Apple's in-house style is the former, and no one submits bug reports for the latter.


I have to admit I stopped fighting it in the end, and started using the style that worked.


In a similar vein, a comment between an if block and and else block used to be mis-indented. This has now been corrected, but comments preceding switch cases are still incorrectly indented.

You can try Swimat - https://github.com/Jintin/Swimat

Simple install by `brew cask install swimat`

Automatic formatting of Swift code
 
 
Q