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 DataXcode 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
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.
Removing the file from the Test Targets fixed my problem.
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.
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.xcodeprojby clicking with Right Mouse Click and openShow Package Contents - Go to
xcuserdataand delete youryouruser.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.xcworkspaceby clicking with Right Mouse Click and openShow Package Contents Go to
xcuserdataand delete youryouruser.xcuserdatadQuit Xcode
- Delete Derived Data by using Terminal:
rm -rf ~/Library/Developer/Xcode/DerivedData
- Open Xcode and check if it works.
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 Navigatorpane - 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
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)
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:
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.
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.
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 :)
Use Command + B
or Command + R to Build or Run the project
Xcode sometimes messes up ;)
- check whether you selected the
Suggest completions while typingin Xcode -> Preferences -> Text Editing - navigate to user->Library->Developer->Xcode->DerivedData in Finder and delete the DerivedData folder
This can also happen if you redundantly named your files. For example,
Data.swift
Data.swift
Build errors can break the autocompletion feature in Xcode.
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 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.
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.
The only time auto-complete doesn’t work is when the source code type for the file is not set to Objective-C or when you’re writing in another language (even if only a little snippet of, say, C).
It also doesn’t work if there is a syntax error on or above the line you are editing. A missing curly brace at the end of a method call—even if it’s not in the file you’re editing–will prevent auto-complete from obtaining the necessary context to suggest relevant commands. So will a missing file (shown in red in your list of files), even if that’s not the file you’re working on.
When it does that, attempt a build to locate errors, and then fix them.
来源:https://stackoverflow.com/questions/46504286/xcode-9-autocomplete-not-working-100-partially-working




