Autocomplete close closure syntax

Does anyone know why Xcode sometimes uses one syntax against another to close closures?

Example:

func someThingWithABlock(block:(() -> Void)) {

    block()

}

This is my preferred syntax:

someThingWithABlock { () -> Void in
    //
}

But sometimes Xcode suddenly gives me this:

someThingWithABlock({ () -> Void in
    //
})

I noticed that Xcode always prefers the second syntax when nested:

someThingWithABlock { () -> Void in
    someThingWithABlock({ () -> Void in

    })
}

But only when investing in another closing circuit:

func foo() {
    someThingWithABlock { () -> Void in
        //
    }
}

I know that they are both essentially the same. But it annoyed me for several days, and now I wanted to find out more and possibly fix it.

+4
source share

Source: https://habr.com/ru/post/1627971/


All Articles