可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
I'm having issues with Xcode being quite unreliable when using the keyboard shortcut to comment or uncomment code ⌘+/. I can't seem to find a real pattern as to when it breaks, but it usually happens after building and running my code on the simulator. It will not work again until I edit something in any one of my code files. Even if I switch to another file in the main view, commenting via shortcut does not work. Other keyboard shortcuts, such as indenting ⌘+[ continue to work just fine.
Do other people have this issue, and if so, have you found a solution? I know it seems like a small complaint, but when running and then quickly trying to comment out a block of code to check the effect, it's a bit of an inconvenience.
I am using Xcode 6.1 (6A1052d) on OXS Yosemite 10.10 (14A389) and developing in Objective-C for iOS if that matters.
回答1:
For an Xcode 8, solution is
sudo /usr/libexec/xpccachectl
and restart your computer.
回答2:
Hit ⌘+] once and then ⌘+/ will start working again.
You can hit ⌘+[ to undo the indentation effect.
Update:
Please note- This solution was provided prior to Xcode 8 launch so it may not work for everyone. If you are still facing problem, kindly refer to @CryingHippo's answer instead of downvoting.
回答3:
I have done this numerous times with Xcode 8. Latest being Xcode 10.1 where I would just quit Xcode and go to Applications and rename Xcode to something else, e.g. Xcode 2, launch it, quit again and rename back. It starts working after that. No Mac restart or Terminal commands required.
It still works as of Xcode 10.1. I cannot believe Apple still hasn't fixed it properly.
回答4:
None of the above solutions worked for me with Xcode 8.0 (final). If you also have Xcode 8.1 beta installed like I do, try this: simply rename /Applications/Xcode-beta.app to something else, then restart Xcode 8. Oddly enough, that did the trick.
回答5:
Oscahie's answer actually works for non-beta versions of Xcode as well. Here are the steps to follow, based on Sam's comment:
- Close Xcode
- In the Application folder, rename Xcode.app (or similar) to Xcode2.app. You might need to type in your password.
- Open Xcode, then close it.
- Rename Xcode2.app back to what it was before.
- (Optional) Spend 5 minutes wondering why this worked.
No need to reboot!
回答6:
I didn't have to do any of the above. A simple reboot fixed it.
回答7:
In my code I had this sequence:
/*" BLABLA MY COMMENTS */
All the code under this was not "commentable".
Removed the " and it was ok !
Hope it helps!
回答8:
I am using Xcode 8.1 (not beta) and I had the same problem, not able to cmd+\ to comment. Restart Xcode not working for me but RESTART my Mac SOLVED the problem without a need to remove cache.
回答9:
Just quit xcode completely and restart. Worked for xcode 8.2
回答10:
A simple workaround works good for me with following steps:
- Comment any line i.e. simply add "//" in front of a line.
- Press Command + "/" and it starts working.
It might help someone.
回答11:
I had this problem in Xcode 8.0. Even though I already move Xcode 8.1-beta somewhere else (It's at Application/Xcode otherversions/Xcode 8.1-beta.app
). I have to delete it to the trash, restart Xcode 8.0, and cmd+/ somehow works again.
回答12:
Nothing above worked, even after trying multiple times.
Just reinstalled new xcode using AppStore app, previously I installed xcode after downloading from
developer.apple.com/downloads. that is .xip
file
Wait for new update and install.
Another reason may be that xcode isn't in Application
directory.
回答13:
I was also facing this issue, when having multiple Xcode installed.
In which Xcode version you are you facing this problem, to solve this, the Xcode should be in the Application Folder. If it resides in the subfolder than move it to the Application folder directly.