Xcode Command-Slash Shortcut to Comment Only Works Sometimes - xcode

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.

For an Xcode 8, solution is
sudo /usr/libexec/xpccachectl
and restart your computer.

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.

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.

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.

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!

I didn't have to do any of the above. A simple reboot fixed it.

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.

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!

I just had the same issue after setting up a new Mac with Xcode 10.1 using the German keyboard layout.
The solution was to disable the Keyboard shortcut in system settings for the help menu.
System settings > Keyboard > Shortcuts > App shortcuts.
There was a shortcut for all apps to show the help menu.
If you have that, click the checkbox to disable it

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.

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.

Just quit xcode completely and restart. Worked for xcode 8.2

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.

I found a pattern where toggle comments do not work.
In fact, uncomment works, but comment don't, from keyboard as well as from the Editor menu.
This happens in a specific file, suggesting there is something in text that prevents from working.
I tested on XCode 10.1ß and on XCode10.2, on different machines.
Text before this line can be commented, text after cannot (I kept text exactly as is)
let alert = UIAlertController(title: "" /*"Teste texte"*/, message: "Love\nWe'll recommend more for you" /* Entrez des chiffres"*/, preferredStyle: .alert)
It appears that the /* … */ inside the UIAlertController() is the cause.
If I suppress both comments inside, everything works OK.
I filed a bug report. # 49907361

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.

Related

Xcode 9 Autocomplete Not Working 100% - Partially Working

This morning, Xcode 9.0 (9A235) shows a new/strange Auto Complete box that is not at all what it used to be. How do I get the full auto-complete box so that autocomplete looks like how it usually does?
Try:
Go to Xcode > Preferences > Text Editing
Under Code completion - Uncheck 'Suggest completions while typing'
Quit out of Xcode and then relaunch Xcode.
Go to Xcode > Preferences > Text Editing again
Quit out of Xcode and then relaunch Xcode.
Now go to Code completion and check 'Suggest completions while typing'.
Try typing library function or enum and enjoy!
Deleting the DERIVED DATA folder seemed to fix my issue. Thanks to this post: swift println() not showing autocomplete options while writting code
Things to try:
#1
Run this command in the project directory if you use cocoapods:
rm -rf ~/Library/Caches/CocoaPods;
rm -rf Pods; rm -rf ~/Library/Developer/Xcode/DerivedData/*;
pod deintegrate; pod setup; pod install;
#2
**Clean Cached Data**
Clean the Project -> Cmd+Shift+K
Clean the Build Folder -> Cmd+Shift+Option+K
If you skipped step one:
Delete Derived Data
Xcode Preferences -> Locations ->
Arrow Symbol Takes you to DerrivedData -> Delete Folder
#3
**Check your Build Phase's Compile Sources.**
Every .swift and .m file in the project should be in this list or it won't autocomplete in those files.
#4
**Optimize your Editor:**
Use fileprivate* on every class property and function that you can to reduce the scope of the Compilers work per item.
Write modular/OOP code so you have less code for the compiler to read.
Avoid using Type Inferance when the result is a complex calculation, and try to break down complex calculations into let this = smallerOperation statements
* In Swift 4 private became stricter than fileprivate
In Xcode 12 there have been significant improvements in how often deleting derived data is necessary (though freezing has increased).
Xcode Version 11.0 (11A420a)
I have tried the solution from Lal Krishna for Xcode V11.0. It worked a few times but later I got no result.
I found one solution. You must delete two files:
Library/Developer/Xcode/Derived Data (as described before)
Library/Developer/Xcode/UserData/IDEEditorInteractivityHistory
That solution helps me now. May be useful for others 😉
This can happen when the file is not a member of the Target. Open the file where autocomplete is not working and show the the "Utilities" tab in the top right of Xcode (blue in the screenshot below).
Ensure your Target (typically your app's name) is checked. Autocomplete should work almost instantly without restarting Xcode, cleaning, or deleting Derived Data.
If it is already checked, make sure to uncheck and recheck it again. For me, it did the trick.
I'm using Xcode 10.2 and I had the same issue.
This answer from axel helped me to fix.
Anyway, I'm going to describe a bit more:
Go to YourProject.xcodeproj by clicking with Right Mouse Click and open Show Package Contents
Go to xcuserdata and delete your youruser.xcuserdatad
If you have also the xcworkspace(if you already have any pods installed) then do step 3&4, if not then just skip step 3&4:
Go to YourProject.xcworkspace by clicking with Right Mouse Click and open Show Package Contents
Go to xcuserdata and delete your youruser.xcuserdatad
Quit Xcode
Delete Derived Data by using Terminal:
rm -rf ~/Library/Developer/Xcode/DerivedData
Open Xcode and check if it works.
This can also happen if you redundantly named your files. For example,
Data.swift
Data.swift
Here's a bit of workaround but works.
Clean the project... Command + Shift + K
Clean the build folder... Command + Shift + Options(Alt) + K
Delete derived data for the project...
This can be done with the help of this link:
How can I delete derived data in Xcode 9?
Close XCode.
Reopen XCode (let the indexing complete) and Build the project... Command + B
Once it will be done with building, The suggestions will be back. I have tried it twice.
Update:
Sometimes the issue can be as simple as Duplicate file names.
Carefully check if any new file names added by you are conflicting with older files.
In Xcode 11.4, even if you move an existing file to another group, the suggestions disappear. This can be cured simply by restarting Xcode.
Removing the file from the Test Targets fixed my problem.
After a long time of searching, I finally fixed the issue for me. In Xcode > Preferences > Text Editing, in "Code Completion", I had "Use Escape key to show completion suggestions" checked for some reason. As soon as I unchecked this box, auto completion worked like a charm, without even needing to restart Xcode! (Xcode 10)
Please try doing this:
Select the file >> check if the file is added to UITesting or UnitTesting targets (File inspector -> Target Membership). If so, please uncheck those two and make sure only the project target is selected. Then build and try if autocomplete is working fine.
This worked for me. Hope it help someone.
For Xcode 11.4 (11E146)
Back Slash in folder name breaking the autocompletion feature, If this is the case remove it and build again.
I added here what was going on in my project just in case it can help someone else... I had 2 files with the same name and I didn't realise.
Just lost a day trying to solve the autocomplete nightmare of Xcode (9.2). Deleting derived data seemed to work briefly then things reverted. Reboots etc and other suggested voodoo failed to make a difference.
I gave up and download the 30 day trial of AppCode from Jet Brains. Autocomplete worked fine there and this maybe coincidence but it then started working again in my project in Xcode. Can't guarantee that it'll keep working...
It seems to be file specific in my case (Xcode 9.2) For me the fix was:
Delete problem file (remove reference)
Clean and Build
Add file back into the project (I did not check test targets)
Build again
Finally after 3 hours of trying everything - autocomplete works as it should.
Problems mostly because there are missing location of some files in project navigator (build errors)
Press command+1 to open Project Navigator pane
Check if there are any missing files
Or you can:
Delete DerivedData (command+shift+K)
Clean build folder (command+shift+option+K)
Press build again (command+B)
You should see build error that Xcode could not find some files that prevent build tool to process auto complete.
Correct and fix any missing files that you see.
Hope this helps
Use Command + B
or Command + R to Build or Run the project
Xcode sometimes messes up ;)
Xcode 11.3, macOS catalina
process parsecd achieve 100% of cpu, so kill it helps me
goto underneath directory and delete all folders on it.
{Your User}/Library/Developer/Xcode/DeriveData
It worked for me.
For me it was happening in my test file, because it wasn't part of a target for some reason. Setting it's target membership solved the issue.
For me, the problem occured when I discarded all the changes of one file (under Source Control > Commit), which effectively deleted the file. This is what I wanted and I thought that the file and all references to it would be delted too.
However, there was still a reference to the file (shown in red) in the Project navigator. Deleting the (now non-existant) file in the Project navigator magically brought auto-completion back.
No amount of cleaning, deleting derived data, etc helped. I only realized the deleted file was still showing when I tried to build my project, which of course failed because it couldnt find that file.
Hope this will help someone save 30 minutes :)
check whether you selected the Suggest completions while typing in Xcode -> Preferences -> Text Editing
navigate to user->Library->Developer->Xcode->DerivedData in Finder and delete the DerivedData folder
My case might appear too specific to help, but it might give someone an idea of how to solve broken auto-completion. Xcode 10.2.1.
In my case, auto-complete stopped working entirely and non of these other answers helped me. In addition, the fan on the computer could be heard to go louder indicating something was overworking (no other apps running), it should be noted I was editing on a MacBook Pro laptop. It seemed to be linked with the editor struggling to parse the equation I'd written:
switch mtype {
case .indeterminate:
newPosition.x = (frame.width - mainFigureText.frame.width) / 2
case .right:
newPosition.x = (((frame.width / 2) - mainFigureText.frame.width) / 2) + (frame.width / 2)
case .left:
newPosition.x = (((frame.width / 2) - mainFigureText.frame.width) / 2)
}
I was looking to animate a text view left, right, or to the middle depending on user prefs. The newPosition is a CGPoint that the text will animate to. Anyway, I split the equations up and all of a sudden auto-complete started working and the fan went quiet! I've been able to recreate this specific problem more than once by re-typing the above code and then replacing it with:
let halfFrameWidth: CGFloat = frame.width / 2
let middleLeft = (halfFrameWidth - mainFigureText.frame.width) / 2
switch doseType {
case .right:
newPosition.x = middleLeft + halfFrameWidth
case .left:
newPosition.x = middleLeft
default:
newPosition.x = (frame.width - mainFigureText.frame.width) / 2
}
I would like to add one more to the pile of solutions, because it is the only one that worked for me and is nowhere to be found here.
Xcode normally comes with two default build configuration for every project. Release & Debug. I have an extra one for my unit tests called Testing. In Xcode 10.1, 10.2, 10.3 and 11 beta, the new build system does not seem to like it and will only auto-complete if you either use Release or Debug. Any custom build configuration breaks auto-completion in mixed (swift + objc) project with unit tests.
I faced the same problem in Xcode 11.3.1. In my case The issue was cause due to duplicate file names / Deleted file name. Better to run the application once and check whether there are any deleted files/classes so that you will get a syntax error.
This Link helped me. Open the Build Settings & fill the framework search paths. See the below image.
Build errors can break the autocompletion feature in Xcode.
I had the issue with 100% not working auto-complete, none of written here helped. One thing I noticed – it was broken right after adding some entities into .xcdatamodel file, which have codegen class definition by default.
So I wasn't surprised when using old-style codegen none (and generating classes of course) fixed the issue immediately, even without restarting the xcode.
With Xcode 11.1, simply performing Clean Build Folder or deleting derived data was not enough to fix autocomplete.
Only after restarting my Mac, everything was back to normal
If you have issue with weird completion/auto-completion/intellisense (not showing default stuff like delegates and datasource protocols methods) just change your target (e.g. from simulator iPhone 8 to real device), build the project and switch back to your original target.
Similar with issues with Interface Builder (storyboards) not showing anything, but only "nothing selected" whenever you select any part of the view. Just switch to other Xib/Storyboard (or even create new), check if it works there and switch back.
These workarounds worked for me in both cases (had both issues in one day with one project on Xcode 10.2.1). From what I've seen all over internet forums it seems these are bugs never fixed since Xcode 6.x or so.
Cheers!

Add Documentation is disabled in Xcode 8

Why "Add Documentation" is disabled in Xcode 8.2? How can I enable it?
This issue seems to appear randomly for myself as well. The only surefire way I've found to re-enable it is to run
sudo /usr/libexec/xpccachectl
in the terminal and restart my computer.
For the making it enable you need to select code first like following gif and you can add documentation based on selection.
It's ridiculous that it still happens even with Xcode 10.1. And it have a ridiculous solution:
Exit Xcode, then rename Xcode.app to something else like Xcode1.app, then back to Xcode.app. For Appstore version you will be asked for admin password.

Xcode Quick Help displays "No Quick Help" when viewing a single file

The quick help feature is working just fine when I open an Xcode project, however when opening a file (e.g. abc.swift) that's not in an open project, the documentation does not appear.
Here is an example:
Install the version of the Command Line Tools for your Xcode
`Xcode menu -> Open developer tools -> More Developer Tools
Restart Xcode. It helped me to see Quick Help again and also fixed git crash.
The below code worked for me. Run the following command from Terminal, then relaunch Xcode.
defaults delete com.apple.dt.Xcode IDEIndexDisable
As an occasional user of XCode, what I still needed to do was download the documentation, which was not installed with the XCode install and/or did not carry over from a previous version of XCode.
From the Preferences dialog, click the Components tab, click on Documentation, and then click the download button for Guides and Sample Code.
Probably obvious for regular users of XCode, but I thought I would write it out for anyone else having this problem, since this was at the top of the Google search.
This is what worked for me. I closed Xcode and then deleted ~/Library/Caches/com.apple.dt.Xcode.
Then I reopened Xcode and checked. It worked after that. I'm currently on Xcode 10.2.1.
It's worked for me, just move the Xcode.app into Applications folder if not exist over here ;)

XCode 6 autocomplete stopped working

XCode 6 Beta 5 and autocomplete stopped working. I thought problem in Beta 5 but I've reinstall to Beta 4 and it's still not work but it did before. I check preferences for "suggests" and I tried to delete Derived Data but it doesn't help
Clear derived data.
Under build settings, select Always Search User Paths to "YES".
Clean the project.
This happened to me recently because I had a /* */ style comment after the #end of my #implementation.
Not sure why that would break autocomplete but moving the comment into the implementation fixed autocomplete.
There seems to be a lot of reasons autocomplete breaks. Just adding to the list..
I found the solution. Problem was in an array.
I have big array like:
let array:[NSString] = ["first","second"...]
I changed it to
var array = ["first","second"...]
I don't why it's happened but it works. It was so hard to find the problem.
I was having this problem.
This is what worked for me.
Clear derived data.
Window -> Organizer -> "Select you project" -> Delete Derived Data.
Clean the project
Quit Xcode ----- this is very important. You might have to restart you computer.
Open Xcode again
Hope this works for you. This worked on 2/9/2015
Check if the .m file has been checked in "Target Membership"
Tried to clean/delete derived data multiple times. Autocomplete was disabled in some files, but not App Delegate. After a while I saw red libraries int he project navigator. Those are managed by cocoapods. The solution turned out to be:
Navigate to the project root folder
Delete "Pods" directory
open terminal, type cd
drag the project folder there to get full path
run pod install
Upon reinstalling pods, syntax highlighting and code completion is restored in the affected files.
For me it was because it was a new problem since upgrading my version of Xcode. After downloading the documentation again, everything worked fine.

iOS5 Storyboard error: Storyboards are unavailable on iOS 4.3 and prior

I've built a small app using storyboards and it ran great. Just before final testing I decided to try it out to see if it runs on iOS 4.3. I clicked on the gray 5.0 in the project settings and selected 4.3.
The app failed to build with the following error message:
Storyboards are unavailable on iOS 4.3 and prior
Both the iPhone and iPad storyboards tell me that.
The issue that when I switched back to iOS5 target, I still keep getting these errors from both storyboards, and the product won't build!
I checked: iOS Deployment target in projects settings is 5.0
Target app deployment target is 5.0
Build settings uses iOS 5.0 SDK
What else do I need to do to restore my project to a buildable state? Is this a brand new bug or am I forgetting something?
Update: I kept getting this error even after doing a clean.
I changed the debugger in Schemes to "LLDB" and did an additional clean, the project now builds and compiles
I also got this problem and finally I solved this by following procedure:
Open XXXXXX.storyboard
Open Identity and Type tab in your right view of Xcode.
Set the value of Development in Document Versioning to "Xcode 4.2" (my default value is "Default Version (Xcode 4.1)".
Change the value of Deployment from Project SDK Version (iOS 5.0) to iOS 5.0, then back to Project SDK Version (iOS 5.0)
Rebuild the project and the error should be resolved.
The solution that worked for me was just to delete the ~/Library/Developer/Xcode/DerivedData directory for my project.
I'm just going to add this one as another possible answer here, as the first solutions worked for me several times (as I mentioned in my previous comment) until today when I couldn't get my project to compile for love nor money with the same error.
With the debugger changed and Xcode set to 4.2 and restarting several times I could not compile. However I discovered another way to get around this issue.
Select the storyboard in the left column and 'Show in Finder' and drag the storyboard to the desktop. Xcode will now change its colour to red and be unable to compile.
Clean the project, drag the storyboard back from the desktop to the directory in finder.
Then, it builds and the error goes away again.
I don't know what triggered the error originally as I'm developing under iOS5 and building for 4.3, but it seems to come up from time to time and.
This seems to be a bug in the latest XCode that I've also run into too, did try the OP's solution of changing debugger and that had no effect.
It cropped up for me since I tried storyboard with 4.3 and then tried to change back.
My solution was to close XCode, open it again and clean. Then I compiled and it worked fine.
Hope this helps others.
While other solutions helped me, they didn't work 100% of the time. I don't know enough about XCode to know how reliable this solution is, but at least it worked for me so you can try it in your project.
In the left hand side of Xcode, open the project navigator. Click the top item, which is your project. In the panel immediately to the right, you'll see a choice to choose between your project and its targets. Click the project, and then in the panel to the right, under the "Info" tab, set "Command-line builds use" to Debug (in my two projects where I was having the error, both were set to Release).
A picture is probably easiest:
Another idea: Open another project with storyboards in Xcode and try to run that. If it succeeds, you can come back to the current project and it should build. I think this clearly indicates a bug in Xcode.
After trying all the answers in here (removing the Storyboard reference, quitting Xcode, cleaning, changing debugger, etc.), none worked (with Xcode 4.5).
The only way I got it to rebuild (and it was a total guess) was to open the Storyboard file in a text editor and delete the following line:
<deployment version="1280" identifier="iOS"/>
It should be near the top of the file, in the <dependencies> section. After that, the project was built successfully and Xcode even re-added that line to the file, but, it still builds...
Go figure...! Hopefully it can help someone!
At last, an elegant workaround that seems to do the trick for me! (I sure hope it works for everyone else. This one's stubborn.)
Once your settings are back safely in iOS 5-land, try Cmd-Option-Shift K (aka "Clean Build Folder..." from the menu - hold down Option to see it), then build.
the solution is simple,
right click your storyboard file, and show in finder
then select the folder where the file is (this would probably be in the en.lproj folder)
right click on the MainStoryboard.storyboard file causing the problem and open with text edit
find the line that reads or something like this:
<development version="4300" defaultVersion="4200" identifier="xcode"/>
and change it to something like this:
<development defaultVersion="4300" identifier="xcode"/>
save the file and build. Et voila...
Ok, I tried everything above and problem still occurred. So I just remove storyboards (as reference not move to trash). then build successfully; after that I added them again; Build, And finally worked.
I was having the same problem. I tried all the above answers and all combinations and nothing worked. Then later after doing some research, I analysed that the simple fact that the error that was throwing at me was straight forward.
Just go to the Build settings and instead of selecting the xcode project file, select the product file and change the Deployment target to 5.0 or 5.1. The error should go off.! I did this in Xcode 4.3 in Lion OSX. It worked fine for me!!
I also had this problem, and nothing helped. Even opening another project and trying to build failed.
What I did, and what for me, was going to project -> info and under "Deployment Target" change iOS Deployment Target to whatever, build and than change back to whatever it was and build again.
Here is yet another random, voodoo, flail that seemed to workaround the bug just now. (after other techniques here had not helped) I renamed the storyboard file (and the entry for it in the info.plist file). Haven't tried the "drag to/from desktop" ritual yet.
Tonight, I have lost like 45 minutes to this issue. grrrrr. Ok I feel better now.
After trying all the suggestions above, without success, I got my code to compile doing the following.
Edit -> Refactor -> Convert to Objective-C ARC
rm -rf $HOME/Library/Application Support/Developer/Shared/Xcode
rm -rf $HOME/Library/Preferences/com.apple.dt.Xcode.*
rm -rf $HOME/Library/Saved\ Application\ State/com.apple.dt.Xcode.savedState
rm -rf $HOME/Library/Developer/Xcode
seems to help with Xcode 4.3.2
Had similar issue. XCode would build and run other projects fine but couldn't get rid of the error on project I had changed, not even backups from server. Tried all the above solutions but nada. Here is what worked.
Uninstall XCode.
Delete user/library/developer/XCode folder.
Reinstall XCode (maybe you should start this before searching for the folder, download took me 20 minutes).
Start up, clean and build.
Worked for me. Saved me some time. Sometimes when the scalpel doesn't work it's time for the hatchet. Now I get to pick a new font to code in (this will clear your preferences)!
The only solution that has worked for me is to create another project without Storyboarding enabled, build it, then switch back to the storyboard project, clean and build.
Here is yet another random, voodoo, disconnect your iPhone if it is connected.
I simple changed deployment target to 4.0 and Development to 4.3 from MainStroyboard.
I clean the project; and restarted the mac, :) i know it sounds funny but restarting xcode didn't helped. maybe there is a cache in memory...
Then i built the project ; it was ok!

Resources