I've been annoyed by Xcode lately since I had to use a few more #if directives than usual. Xcode always wants no indentation between directives such as #if.
#if DEBUG
foo() // Xcode's preferred style
#endif
I tend to write:
#if DEBUG
foo()
#endif
control + i shortcut in Xcode always messes up the whole indentation (not only for directives).
So I'm asking for clarification from the community. What is the correct or preferred indentation for such code?
I wish that Xcode was also open-source so that the community could provide fixes to such small annoyances which probably are very low priority for the Xcode team itself.
I have gone back and forth over the years and settled on keeping them inline in order to reserve indentation to indicate a change in scope (ie: a closure, function, new type, if-else/switch, etc).
I do see the benefits of either method though, which is why I wavered between them over the years.
I tend to not indent the directives, and leave the body matching the enclosing indentation, to show what it'll look like after the #if has been folded away. That's probably a holdover from C-land, though, where #if happens so "early on" that you can stick half a statement on one side and half on the other and the compiler says "sure, okay".
I do the same, basically for the same reasons. This does make me think about the way availability checks work though. These are used in patterns which create scopes, but you get a compile-time guarantee of which scope will actually be entered at run time.
I think I would actually prefer if this worked the same way as #if to be honest (would let you use availability checks in patterns where, syntactically, they currently can't be). But I'm sure there are reasons for it to be like this.
There more such things. Some of them happen when you type the # character. Xcode will also completely break multiline formatted JSON strings. guard else is never indented correctly.
You should file bugs for those at bugreport.apple.com under "Developer Tools/Xcode", but it's super annoying it takes so much effort and time for so simple "bugs"
I recently filed a bug about how Xcodeās automatic indentation strips the leading whitespace from all lines of a multiline string literal, if thatās what youāre referring to. It was marked as a duplicate of rdar://problem/20193017