Xcode 6 isn't autocompleting in Swift
Asked Answered
P

10

63

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?

Poon answered 5/8, 2014 at 7:8 Comment(0)
G
143

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…

Glazier answered 27/10, 2014 at 20:33 Comment(10)
Thank you! But for reals, what is up with Xcode6 anyway? It's just so damn buggy! C'mon Apple...Jockstrap
It worked, but it's very sad that this bug exists on 23rd December, when this post was open on 5th August.Doubt
Worked for me without restarting the computer. THANK YOU. That was driving me bonkers.Arand
works without restart! spent so many hours on this.. thanks mate!Schmidt
Did not work for me when using Xcode 6.2 - Objective C project with Swift classesGarber
you solution solved my problem, but its appears again after sometime . if you have permanent solution then please post . thanksRagin
Just tried it in 7.1.1 and it definitely sped up my autocompleting.Glazier
Just used this trick to fix broken swift autocomplete in Xcode 7.2. And my cache file was nearly 5GB!Chromatism
Step 4 (without restart, etc.) saved me on Xcode 7.2. Thank you!Herbage
Confirmed that it still works in 7.3. Thanks so much!Interdiction
Y
67

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.

Yiddish answered 19/2, 2015 at 17:30 Comment(5)
I Couldn't Find the Folder Directly, therefore, THIS WAS the Correct Solution for Me... THANKS :-)Keratose
Perfect solution for me!!Adah
This works for me. I didn't even close the Simulator.Pleiades
Strange; worked for me in Xcode 7.2. Check similar questions: other people are having problem when trying to autocomplete classes imported from eternal frameworks. That requires a different solutionHerbage
Once you delete your derived data and run Xcode again you should build you project, at least it worked for me. I had a bug where autocomplete didn't worked at all, I deleted derived data, nothing changed then I built the project with UITableViewDelegate but no methods implemented. XCode gave me errors and then for some reason after that autocomplete was back.Civilian
N
17

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

Nammu answered 24/10, 2014 at 4:2 Comment(1)
Still happens with Xcode 6.1.1. This solutions works.Devol
E
5

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)

Exhibition answered 14/5, 2015 at 15:48 Comment(0)
C
3

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!

Cheekbone answered 5/8, 2014 at 18:7 Comment(1)
Its really annoying and disappointing using such a new language with minimal documentation and the code completion isn't working. I hope your rightPoon
A
2

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.

Alpaca answered 5/8, 2014 at 7:46 Comment(2)
Is there any way to update my current XCode6 or do I need to download from apple and reinstall?Poon
@AvnerBarr Download the whole new beta and install it. Then manually delete the old one if you don't need it. That's just the way the betas work. The Apple Developer Blog posts an update when a new beta is available, so if you use an RSS reader, it's worth subscribing to.Tubing
U
2

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 :)

Unpaidfor answered 19/3, 2015 at 9:12 Comment(3)
Replace /Users/iphonedev5/ with $HOME/Michellmichella
I wrote this about a year ago, however you are completely right. No need to hard code this.Unpaidfor
Also replace single quotes with double quotes for that line :-)Michellmichella
L
1

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

Linet answered 15/6, 2015 at 8:57 Comment(1)
I'm upvoting you because this is the weirdest, most unexpected, most seemingly unrelated fix to this problem! ;)Herbage
W
0

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

Wrath answered 5/8, 2014 at 7:9 Comment(0)
O
0

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.

Overstay answered 19/12, 2014 at 16:24 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.