user3267254
user3267254

Reputation:

How can I get Xcode 6 to indent switch statements properly?

When editing an Objective C file, the autocomplete snippet for the Switch statement looks like this.

(wow, i'd love to put the code here, but this page complains that it isn't properly formatted, which is the problem i'm asking about 9_9)

outdented switch statement

I want the case labels lined up with the switch statement. I'll even settle for the case labels indented one level.

My problem is that reinstalling Xcode doesn't fix the problem. I even used this App Cleaner app (found from the answer to a question about reinstalling Xcode here on stack overflow) to remove files associated with XCode.

I believe this problem is specific to me (instead of a bug in Xcode), because other people I ask about it don't know what I'm talking about.

So how can I get my Xcode behaving properly?

Btw, the snippet looks weird, because it's indented two spaces (I use tabs at a width of 4 spaces for my editing).


I actually got a hint from the person who allowed images in this post (I don't have a high enough score to put images).

I indent using Tabs, with a Width of 4 and Indent of 4. My problem, when the Case label are outdented, is that the switch statement is indented one tab, but the case labels are indented 2 spaces. This matches the second image where the snippet shows them indented 2 spaces.

Assuming this is just a problem with my Xcode, what I'm asking is how can I completely get rid of it and have a normal install (I tried reinstalling). On the other hand, if others have this problem too (that is, it's a bug in XCode), then I'll submit a bug report to Apple.

Two space indent

Upvotes: 1

Views: 1299

Answers (3)

OlDor
OlDor

Reputation: 1466

You would like to edit the standard Xcode snippet, but Xcode doesn't allow you to do this?

Well, it looks like the right time for Snippet Edit.

It will allow you to do anything with the code snippets.

For example, my switch statement looks like this:

enter image description here

Upvotes: 1

user3267254
user3267254

Reputation:

I had the same problem on a Mac at work, then concluded that it is a bug. What weirds me out is that I've been unable to get anyone on the internet to confirm it. Perhaps I didn't explain the issue well. Nonetheless, I submitted a bug report to Apple and it's currently marked as a Duplicate of another bug that is Open. So I expect it will be fixed.

In case anyone who comes across this is unclear on what the bug is, the bug is that the code completion snippet indents the Case label at 2 spaces. I happen to indent using Tabs, but it still indents at 2 spaces. With my tab set to a width of 4 spaces, this causes the Switch statement to indent farther than the Case label when using the auto complete. This problem is masked if you indent using Spaces, because even though the snippet indents two spaces, it will line it up with the next "tab" stop at 4 spaces (or 8 spaces, etc.).

Interestingly, it only happens when using the snippet for Objective-C. This problem doesn't occur with Swift.

Upvotes: 1

dfinki
dfinki

Reputation: 342

Try checking the Indent width at 4 spaces.

You find the following screen under "Xcode-Preferences"

enter image description here

Posted as an answer, cause comments don't have images.

Upvotes: 2

Related Questions