56

For some reason, in Xcode 8.2 my code completion has stopped working. I have cleaned my product, restarted Xcode, restarted my computer, and deleted the derived data, and still no luck. I have submitted this to Apple Support. Has anyone run into this before and been able to fix it?

Paul Brinkley
  • 6,283
  • 3
  • 24
  • 33
ethanfox27
  • 890
  • 1
  • 9
  • 25
  • 2
    Try switching the deployment target. – shallowThought Dec 19 '16 at 17:23
  • 3
    Make sure your interface builder is not open. I have found the constant rebuilding caused by leaving IB up while writing code slows/breaks many things including code completion. – AnthonyW Dec 19 '16 at 17:40
  • 1
    @AnthonyW You can disable that. Turn off "Automatically Refresh Views" in the Editor menu. You can then manually refresh views whenever you want your IB_Designables to refresh. – siburb Apr 16 '17 at 02:52
  • try hitting enter or closing other tabs and then waiting up to 5 seconds – mfaani Oct 30 '17 at 19:15
  • 1
    Accept this [Answer](https://stackoverflow.com/a/42380489/4061501) ,please – Lal Krishna Jan 11 '18 at 06:17

9 Answers9

158

Update: As per @Dareon solution below also works for Xcode Version 8.3 (8E162) and 8.3.2 (8E2002). Thanks, @Dareon for the confirmation. :)

I was facing the same issue and following worked for me.

I am using Xcode Version 8.2.1 (8C1002).

  1. Go to Xcode > Preferences > Text Editing
  2. Under Code completion - Uncheck 'Suggest completions while typing'
  3. Quit out of Xcode and then relaunch Xcode.
  4. Go to Xcode > Preferences > Text Editing again
  5. Quit out of Xcode and then relaunch Xcode.
  6. Now go to Code completion and check 'Suggest completions while typing'.
  7. Try typing library function or enum and enjoy!

At least, it worked for me.

Chinmay
  • 1,714
  • 2
  • 11
  • 5
  • 2
    Interesting... This works. I tried first without restarting Xcode which did not work at all. Without the code completion feature I am completely lost.. – akw Mar 27 '17 at 09:09
  • 1
    Unfortunately I'm having the same issue on Xcode 8.3.3 - any other suggestions? – Andrew Lombard Jun 14 '17 at 11:52
  • Hi @AndrewLombard, sorry for late reply. Try closing and reopening after step 4. That might help. It's strange, as I used same steps to fix it on my Xcode 8.3.3. Let me know how you go. – Chinmay Jul 04 '17 at 14:29
  • Worked form me in 8.3.3, however I think I now prefer to just leave 'Suggest completions while typing' off and use control-space when I want suggestions. BTW, this also fixed the command-click on a protocol name - it was failing to open the documentation. – lost baby Jul 18 '17 at 11:07
  • 1
    I've been fighting with this since Xcode 7. I can't do enough to thank you. – Erik Bean Aug 22 '17 at 18:02
  • 3
    Can we make this as the correct answer? It saved me a lot of time. Have been facing this for a couple of days now. – Parin Shah Aug 27 '17 at 00:30
  • 1
    are you dev in Apple who know this shit to make it working :D :P – Fahim Parkar Oct 08 '17 at 09:44
  • @FahimParkar, unfortunately no... :) I would call it - 'necessity is the mother of inventions' kinda scenario... I have lost few hairs before finding this solution. :P – Chinmay Oct 09 '17 at 11:10
  • Works on 9.2 :] – Lal Krishna Jan 11 '18 at 06:27
  • @Chinmay Not working for me in Xcode 9.2 (9C40b). follow the all above step 3 to 4 times but it's didn't work. – vipinsaini0 Apr 09 '18 at 07:27
  • Works on 10 Beta 2 – IceFire Jul 03 '18 at 13:32
  • Worked on XCode 11.0 – Amal T S Nov 04 '19 at 06:23
15

Code completion also stopped working for me in Xcode 8.2.1, and no amount of clean-up, derived data throwaway or restart fixed it. After a while, I realized code completion was only broken within the extension scope I was working on. If typed manually, the code would be correctly highlighted and would compile fine, so it was not an issue of the source throwing off whatever parser is in charge of code completion.

Here is the specific context in which it happens, in this very simple example:

struct SomeStruct {

    static let foobar1 = {
        return NSBezierPath()
    }()

}

extension SomeStruct {

    static let foobar2 = {
        return NSBezierPath()
    }()

}

Code completion works fine within the implementation block of foobar1, but not for foobar2. It's the presence of a static let within an extension that seems to trigger it. The issue appears for both struct and class.

Looks like a bug with Xcode, so the only workaround for me was to move foobar2 into the main definition of SomeStruct.

charles
  • 11,212
  • 3
  • 31
  • 46
  • Have you filled a bug report with Apple? – nbloqs Jan 13 '17 at 16:35
  • 1
    nope! for me it does not work even within any swift class. I am using XCode 8.2.1 and Xcode 8.3 both. – crypt May 22 '17 at 02:21
  • While my answer is the accepted answer, it's just because it happened to be the situation the OP was facing (note how the OP mentioned he deleted the derived data, restarted Xcode, etc). It's definitely not the most common cause for problems with autocompletion, just something to consider if none of the most obvious solutions work. – charles May 23 '17 at 07:31
5

Just restarting Xcode worked for me.

shim
  • 9,289
  • 12
  • 69
  • 108
Display Name
  • 4,502
  • 2
  • 47
  • 63
2

Just clean and build your app once on Generic iOS Device, it might be due to some compile time issue, which disables the intelligence, I am seeing this bug since Xcode 8.2.1.

shim
  • 9,289
  • 12
  • 69
  • 108
Rein rPavi
  • 3,368
  • 4
  • 22
  • 32
2

What worked for me was deleting derived data:

Xcode Preferences -> Locations -> arrow symbol takes you to "Derived Data" -> delete folder

shim
  • 9,289
  • 12
  • 69
  • 108
user1105951
  • 2,259
  • 2
  • 34
  • 55
1

I have had major issues with this as well. For me the code completion and formatting gets lost on my current working source file when ever I do a compile. If I go back and switch to a different tab and come back, after a second or two it starts working again. Sometimes even that doesn't work and I have to stay in the same tab and open up a different file and then navigate back.

Even those methods fail if I leave Xcode open and put the computer to sleep for a few hours and come back. When that happens I have to quit Xcode, sometimes Force Quit it, and then after getting back in do the steps above. But I have had to mess around with it after every single compile or compile and run I do. Haven't tried 8.3 beta yet.

bdepaz
  • 434
  • 1
  • 3
  • 9
0

I had the same issue where the "indexing" did not work. As I was using a pod and static libraries. What I did just rebuild the static libraries separately.

Hope this helps.

0

If you have any large static literals, try commenting them out. Those can sometimes trip up the compiler.

Eden
  • 1,782
  • 15
  • 23
-1

Nothing else worked for me, but this bizarre approach did:

  1. Quit Xcode
  2. Go into your home directory, which if you're like me, is riddled with empty directories with garbage names
  3. rmdir * (as long as you leave the tags off, this will kill only empty directories, which is what you want)
  4. Launch Xcode, happy times again
Matt Channon
  • 119
  • 1
  • 5