March 2017
Intermediate to advanced
226 pages
5h 13m
English
Xcode does a particularly bad job of visually formatting guard statements, especially when you include many conditions within one statement. The IDE doesn’t align the first clause with the rest of the clauses unless you’re using some kind of wacky six-space indentation. At the same time, Xcode aligns the else with the final condition clause and not the parent guard and it adds an extra level of indentation to the body of the else clause. Here’s an example of how a guard statement looks using default layout:
| | guard !arguments.isEmpty, |
| | nums.count == arguments.count |
| | else { |
| | // ... leave scope ... |
| | // (notice the indentation level) |
| | } |
It’s always a good idea to place individual conditions onto their ...
Read now
Unlock full access