58

Using Xcode 6 GM seed my code completion has stopped working. It was working the other day. I was trying to get the unwind segue work around to work. I had made an Objc header file and assigned it as a header for a Swift class.

At this point I get code completion with an Objective-c project. But, not with a Swift project.

I have tried restarting Xcode, making a new empty project.

Mitchell Hudson
  • 1,013
  • 2
  • 10
  • 19

13 Answers13

103

Just go in user->Library->Developer->Xcode->DerivedData and delete the Data of folder(Derived data) and restart Xcode.

Ali Raza
  • 2,796
  • 1
  • 20
  • 24
  • 1
    Just use the above solution followed by a system reboot. Works for me every time with Swift + Xcode 6.1.1. – 4aRk Kn1gh7 Jan 30 '15 at 06:17
  • I am facing the same problem. I don't have `user->Library->Developer->Xcode->DeriveData` . How can i solve this? @Ali Raza – Alamin Apr 20 '15 at 18:24
  • You have an option "Go" before "Window" on the top of the screen of the Desktop. So click on "Go" then you see "Home" click on it and you will find user->Library ... etc @bir – Ali Raza Apr 21 '15 at 05:04
  • When i click at "Home" it shows like this https://dl.dropboxusercontent.com/u/168659703/Screenshot%20at%20Apr%2021%2012-49-21.png @AliRaza – Alamin Apr 21 '15 at 06:52
  • 1
    Ok. Actually Library folder is hidden for that you follow this link http://computers.tutsplus.com/tutorials/how-to-reveal-your-library-folder-in-lion-or-mountain-lion--mac-31972 @bir – Ali Raza Apr 21 '15 at 09:27
  • This problem occurs as well while using Swift with Xcode 6.2. The above seems to fix it. – Alex Apr 30 '15 at 18:16
  • Holy crap Apple. I followed the directions in here over and over and it only worked when done in these exact steps: 1) Quit xcode, 2) Delete Derived Data and com.apple.dt.Xcode directories 3) Reboot. Only then did it work – Constantine May 15 '15 at 02:55
  • @Constantine Thank you for the suggestion. –  Jun 29 '15 at 21:27
  • 1
    "user->Library->Developer->Xcode->DeriveData" - isn't it DerivedData (with a d) – Warrick Feb 12 '16 at 02:32
  • @user3109468 yes you are right. I was wrong. Thanks for your suggestion – Ali Raza Feb 12 '16 at 11:23
27

This fix from apple dev forums works for me. I have had autocomplete issues with Xcode 6.1/Yosemite.

  1. Quit Xcode.
  2. Restart the computer (this is to clear any in-memory caches).
  3. Delete the contents of the DerivedData folder (~/Library/Developer/Xcode/DerivedData), precisely run, a) cd ~/Library/Developer/Xcode/DerivedData/
    b) rm -rf *

  1. (Try this if Steps 1-3 dont really work as it rebuilds the cache later on restart which takes time) Delete the contents of folder ~/Library/Caches/com.apple.dt.Xcode, i.e.,
    a) cd ~/Library/Caches/com.apple.dt.Xcode
    b) rm -rf *

Now launch Xcode once more…

Anuj
  • 6,987
  • 3
  • 22
  • 25
  • This should be the accepted answer. For anyone curious, I was able to delete the ~/Library/Developer/Xcode/DerivedData folder and also com.apple.dt.Xcode from the Finder without hurting anything. I also deleted com.apple.dt.Xcode.sourcecontrol.Git but not sure if it was necessary (if someone was able to leave this one, please let us know). – Zack Morris Jan 08 '16 at 19:25
  • This is exactly what I needed. Steps 1-3 were enough for me. I believe the trick is in deleting the ModuleCache folder inside the DerivedData folder. Thanks! – jervine10 Apr 01 '16 at 15:54
  • 2
    Well this does fix it, but the problem keeps coming back and I have to delete the cache over and over again. This seems to be fixing the symptom and not the problem. – jervine10 May 02 '16 at 20:03
18

I experienced a serious breakdown of code completion because I had some 'notes' after the @end statement of my .m file which were as follows:

/*
 NSAlertFirstButtonReturn, NSAlertSecondButtonReturn, NSAlertThirdButtonReturn
 */

These lines can appear before the @end statement without destroying code completion.

William Price
  • 4,033
  • 1
  • 35
  • 54
NSBob
  • 191
  • 1
  • 3
  • 3
    This was actually my problem too. This is astounding and a terrible bug. This answer was down voted, but definitely deserves attention!! – bkbeachlabs Feb 28 '15 at 05:40
  • I had the same issue and this fixed it perfectly. – user3192649 Jul 28 '15 at 07:56
  • This needs its own question and answer and needs to be on top. I can't believe this was the cause of half a days worth of trouble. – BFeher Oct 27 '15 at 05:44
  • Just wanted to pile on here and say this was exactly my problem as well. The autocomplete would give suggestions like "CGRectMake" but wouldn't completely the function parameters, and in other cases wouldn't autocomplete anything at all. I had a large chunk of commented-out code after @end in my file and moving it after the comment solved it. – Mike Rundle May 09 '16 at 18:02
  • Astounding. I had the same issue and tried the accepted answer but no go. Then I read this and low and behold, it fixed it. Stupid bug. I'll have to go file (probably a duplicate) against Xcode. (Xcode 7.3 in my case) – chadbag Aug 15 '16 at 20:16
7

There's an easier way to delete the Derived Data from within Xcode (no need to open finder or restart):

Xcode Organizer -> Projects -> (Your Project) -> Delete Derived Data

Oren
  • 5,055
  • 3
  • 34
  • 52
  • Much more convenient. Worked for me in Xcode 6.1.1. Thanks! – Clifton Labrum Feb 13 '15 at 18:14
  • This only deletes the data of your project and not the whole Derived Data folder. This works sometimes for me but occasionally you need to delete the whole folder to get it back up and running. – Jeremiah Mar 26 '15 at 14:28
5

I just recently had this problem. Autocomplete did not work ...and when i typed for example tableView.... it did not give me the different functions available.

I tried the following and it worked for me.

  1. Xcode Organizer -> Projects -> (Your Project) -> Delete Derived Data

  2. delete the file ~/Library/Developer/Xcode/DerivedData/ModuleCache

  3. Restart xcode

Hope this works

TheRealRonDez
  • 2,807
  • 2
  • 30
  • 40
4

Another possible reason why it isn't working is because it's not part of the target membership. To fix this, select the file you're working on. Then, go to the File Inspector and in the Target Membership section, make sure your project is checked.

Target Membership

Donn
  • 1,680
  • 14
  • 17
  • 1
    Thanks man, in my case i added a new target and both are selected, when deselect the new target, works!!!!!, but i not have idea why... – jose920405 Sep 09 '16 at 21:51
2

Try the following - as silly as it may sound: Change Device to iPhone 6, close Xcode, Reopen Xcode and wait for the indexing to finish.

Timm Kent
  • 1,123
  • 11
  • 25
1

Go to Xcode menu, then Window -> Organizer, then select Projects. Pick your project and press on delete button beside dervied data Then restart Xcode

That solution worked with me on Xcode 6.1

ossamacpp
  • 656
  • 5
  • 11
1

If your code completion problem is only with UI classes (e.g. UIImage, UIDevice), then you just need to add "import UIKit".

Swift files will NOT have code completion for UI classes unless there is an "import UIKit".

chow
  • 393
  • 4
  • 11
1

I had the same issue but under different circumstances, I have 2 projects in my workspace

  1. Swift framework for iOS and OSX
  2. iOS Project (which uses the swift framework)

My code completion works fine in iOS but it keeps failing in the swift framework. I tried all the about solution and had no luck and was killing my productivity.

Finally i figured out the solution to this problem.

  1. Select the file you are editing (in the framework )
  2. Select the 'utilities' tab on the right
  3. uncheck the Mac target (just keep the target you are working for currently)

Thats it, this solved my problem. hope it helps someone who is in this kinda situation.

spaceMonkey
  • 4,475
  • 4
  • 26
  • 34
  • But, if i need have selected both target? you found solution for that? – jose920405 Sep 09 '16 at 21:53
  • @jose920405 what you mean you need for both targets ? your code is the same for both targets right ? so while coding just select yours, when building just add all the targets and build thats it. Till apple fixes this issues lol – spaceMonkey Sep 10 '16 at 06:57
1

user/Library/Developer/Xcode/DerivedData Delete all the files shown in this folder. after that go to your project name and clean project then come back to the file where you wanna see suggestions. Type any word and its done.

MRizwan33
  • 2,723
  • 6
  • 31
  • 42
0

So all you have to do is make sure, in the file inspector view on the right side, under Target Membership, the first box is checked. I'm not sure why this changes things but I'm sure someone can come along and give a more complete answer.

0

In my case Some File(s) were deleted in File System but were still referenced in the Project i.e. in Red Color. Just delete those from Project and everything was fine. Code Completion started working.

Also Like to point that all the above answers about Clearing/Deleting Derived Data folder seems to work momentarily but whenever there was a new pull or update the problem started again, so the root cause was the unreferenced/moved/deleted files which show up as RED in the project, they needs to be manually cleared.

ioopl
  • 1,735
  • 19
  • 19