简体   繁体   中英

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)

突出的切换语句

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.

两个空格缩进

Try checking the Indent width at 4 spaces.

You find the following screen under "Xcode-Preferences"

在此处输入图片说明

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

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.

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:

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM