Swift switch/case indentation is incorrect
| Originator: | danielctull | ||
| Number: | rdar://24105850 | Date Originated: | 08-Jan-2016 11:51 AM |
| Status: | Open | Resolved: | |
| Product: | Developer Tools | Product Version: | Xcode 7.2 |
| Classification: | UI/Usability | Reproducible: | Always |
When writing a switch statement in Swift, Xcode defaults to indenting the cases as such:
let vegetable = "kale"
switch vegetable {
case "chocolate":
return "Not a vegetable at all."
case "banana":
return "That's a fruit…"
default:
return "Yes \(vegetable) is clearly a vegetable!"
}
While it seems like this style does have some past usage, Xcode has classically indented C code such that the cases are indented one level. This should be applied to Swift as well, which would give the following style:
switch vegetable {
case "chocolate":
return "Not a vegetable at all."
case "banana":
return "That's a fruit…"
default:
return "Yes \(vegetable) is clearly a vegetable!"
}
I have also attached an image of The C Programming Language by Brian Kernighan and Dennis Ritchie, which shows their preference for the latter method of indenting the case statements.
Comments
Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!