Xcode 6 isn't autocompleting in Swift

IosXcodeAutocompleteSwift

Ios Problem Overview


I am trying to import various libraries which I can't remember their exact name. Unfortunately Xcode 6 (using swift) isn't auto completing them like was done in Xcode 5 using objective-c.

For instance:

ALAssetsLibrary
MPMediaPlayer

etc.

I am forced to Google the exact framework name and then go back and copy paste.

In general autocomplete is working very poorly. Am I doing something wrong in Xcode 6?

Should I set any flags in settings to get it to work?

Ios Solutions


Solution 1 - Ios

This fix from apple dev forums works for me. I have had performance/autocomplete issues since beta 5 i think and now xcode 6.1/Yosemite on my old 2010 MBP is working flawlessly.

  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)
  4. [This is the key move:] Delete ~/Library/Caches/com.apple.dt.Xcode.

Now launch Xcode once more…

Solution 2 - Ios

This is the same as the correctly chosen answer above but just made slightly easier.

I've had to do it several times and in my testing you can skip restarting your mac.

  1. Close Xcode

  2. Terminal -> rm -rf ~/Library/Developer/Xcode/DerivedData/*

  3. Terminal -> rm -rf ~/Library/Caches/com.apple.dt.Xcode

Restart Xcode and it should be back to normal.

Solution 3 - Ios

I find that if my deployment target is 8.1 then autocomplete always works. But it is unreliable if it is not.

enter image description here

Solution 4 - Ios

The easiest way to improve xCode speed and to reuse the trick is by creating an alias and call it every time you need it:

1.Open Terminal:
2.Type in to your terminal ( or copy and paste ):
alias xcodeclean="rm -frd ~/Library/Developer/Xcode/DerivedData/* && rm -frd ~/Library/Caches/com.apple.dt.Xcode/*" 3.Final step is to type xcodeclean (Remember: next time when you want to clean the xCode just call xcodeclean)

Solution 5 - Ios

I have had this happen quite a bit, and yes making sure you are on the most recent beta version does help. Unfortunately you have to download the newest one through the developer portal each time.

I have also noticed that the the autocompletion goes away when the swift compiler is struggling with compiling something even though it is error free and if you comment out or remove the right line of code the feature comes back as expected. Most definitely resulting from beta quality software.

A last week I was beating my head against the wall because the swift compiler wasn't playing nice with the sqrt() function. Hopefully these issues are ironed out by the time of full release.

Sorry there's no real 'fix' yet!

Solution 6 - Ios

Sometimes it doesn't autocomplete for me either. I think this is due to the fact that Xcode 6 is still in beta. Btw, have you been updating Xcode 6 beta? The latest is beta 5 at the moment. I failed to notice for some time that the App Store does not update Xcode 6 beta, so I was stuck with beta 1 for a while. If you haven't been updating it, then do it. Maybe that will help with bugs like this.

Solution 7 - Ios

I find this extremely annoying. Posted answer to clear derived data works bulletproof, however you should close xcode before clearing folder. I've made small script to do the work for me.

#!/bin/bash

echo "Start fixing xCode"
echo "Closing xCode"
osascript -e 'tell app "Xcode" to quit'
sleep 2
echo "Clearing DerivedData..."
rm -rf "$HOME/Library/Developer/Xcode/DerivedData"
sleep 2
echo "Launch xCode again"
osascript -e 'tell app "Xcode" to run'
echo "Finish fixing xCode"

Now whenever xCode gives me a finger I simply run it. The problem that you need to recompile everything however still persists.

EDIT

Thanks to on suggestion in the comments from @Nikolay Spassov, I adjusted the script to capture your home directory instead of changing it. So below step is no longer neccessary.

OLD Step

Please note you have to change '/Users/iphonedev5...' part to make it work in your system :)

Solution 8 - Ios

I tried changing the Fonts & Color to default and it worked. I normally have it on MidNight2.

Solution 9 - Ios

I tried all of these, but to no avail - nothing worked. My situation is I have a Swift class "A" that after performing a large merge into my branch could no longer see several other Swift files ("B" - "F") that were located in a different Group from within my project.

What's interesting is "A" belongs to both the main project Target, but also to the UnitTest Target whereas "B", "C", "D", "E", and "F" ONLY belonged to the main project Target.

> By including them for membership with the UnitTests also all of a > sudden Xcode can now see those classes correctly - must be members in the same Targets, perhaps?

The fixed a couple of things:

  1. Code completion now works.
  2. The little red error markers that are next to the line numbers ("unresolved identifier" errors) cleared up too. This last one was very annoying to me as when you CMD-B to build they clear up and the code compiles just fine / runs just fine. But, make ANY change (add a single white space, for example) and these reappeared all the time (and, of course, Code Completion would stop working again as well).

Not sure if this is a Swift or Xcode issue but this is what fixed it for me.

Solution 10 - Ios

If you can't locate all the folders mentioned above or you are too lazy to type in the terminal try the following below:

•Create a new folder on desktop

•Go to your application folder copy the Xcode application

•Paste the application in the folder you created on the desktop

*Go back to the application folder again and delete Xcode from the application folder. You can delete the Xcode app by using cleanMyMac2 or any other cleaner app so that all such files like com.apple.Xcode and others with go it.

•After you have done that restart your computer

•Go to the folder you created early open Xcode you will see the terms and conditions just accept and start your projects

Good Luck

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionAvner BarrView Question on Stackoverflow
Solution 1 - IosbWlrYWphdWhvbmVuView Answer on Stackoverflow
Solution 2 - IosTravis M.View Answer on Stackoverflow
Solution 3 - IosSteve RosenbergView Answer on Stackoverflow
Solution 4 - IosDardanView Answer on Stackoverflow
Solution 5 - Iosjaco129View Answer on Stackoverflow
Solution 6 - IosnotadamView Answer on Stackoverflow
Solution 7 - Ioshris.toView Answer on Stackoverflow
Solution 8 - IosProgr3ssView Answer on Stackoverflow
Solution 9 - IosBonanzaDriverView Answer on Stackoverflow
Solution 10 - IosMalikView Answer on Stackoverflow