Xcode 6 Swift code completion not working

Xcode 6 Swift code completion not working

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. 

Solutions/Answers:

Answer 1:

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

Answer 2:

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…

Answer 3:

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.

Answer 4:

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

Answer 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

Answer 6:

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

Answer 7:

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.

Answer 8:

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

Answer 9:

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”.

Answer 10:

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.

Answer 11:

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.

Answer 12:

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.

Answer 13:

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.

References