101

Maybe this is just me experiencing such an annoying "feature":

After upgrading from Xcode 6.0.1 to Xcode 6.1, things changed. Xcode 6.1 is forever indexing the project or compiling source files. The project is not a huge one. It just contains a bunch of Swift files and AWS SDK 2.0 Cocoapods in the workspace. I don't think it should prevent the whole to index and compile smoothly. I tried with some aws-sdk-ios-samples, just to see how Xcode 6.1 works on them, and it ended up in the same forever waiting.

What solutions I have tried so far:

  1. Deleting "Derived Data" in the Organizer, and re-open and workspace. (fail to fix)
  2. "Show Package Contents" on the .xcodeproj file and deleting .xcworkspace as in (Xcode 4 - slow performance)

None of them worked, unfortunately.

P.S. maybe I should try re-creating the project? My computer settings: MacBook Pro (Retina, 13-inch, Mid 2014), Memory 8 GB 1600 MHz DDR3, with Yosemite. (I think this is enough for running this small project.)

Cœur
  • 32,421
  • 21
  • 173
  • 232
leonard
  • 2,237
  • 4
  • 17
  • 26
  • Similar expierences? Yes: [Xcode beta 3 Swift indexing forever](http://stackoverflow.com/questions/24782721/xcode-beta-3-swift-indexing-forever) – zisoft Oct 21 '14 at 19:17
  • 2
    I won't be of much help but what I do is... I just let xcode 6.x take it's time. If i fight it, it screws me over big time so I just wait till xcode 6 starts. I let it run it's stupid indexing. I then start the iOS simulator separately and wait till it's stupid springboard shows up. Finally when I run a project, I overlook the fact that many times the Indexing says "Paused" and I pray to , drink coffee and try to enter zen mode. But \*sigh\*, it's rough :/ and I had really liked xcode 5.1.1 :| – staticVoidMan Nov 29 '14 at 20:13
  • This answer worked for me: http://stackoverflow.com/a/33395844/242933 – ma11hew28 Dec 15 '16 at 18:22

25 Answers25

72

I tried many of the suggestions above including splitting files, installing Xcode 6.2 beta, and breaking string concatenation statements. What finally did it for me was splitting an array of dictionaries literal declaration I was using for test data into multiple .append statements.

// This causes indexing/building to hang...
var test = [ [ "a": false, "b": "c" ],
             [ "a": false, "b": "c" ],
             [ "a": false, "b": "c" ],
             [ "a": false, "b": "c" ],
             [ "a": false, "b": "c" ],
             [ "a": false, "b": "c" ] ]

// This works fine.
var test = [ [ "a": false, "b": "c" ] ]
test.append([ "a": false, "b": "c" ])
test.append([ "a": false, "b": "c" ])
test.append([ "a": false, "b": "c" ])
test.append([ "a": false, "b": "c" ])
test.append([ "a": false, "b": "c" ])

Also, for what it's worth, the 6th entry in this array is what causes the issue for me; five works just fine.

Zen
  • 821
  • 5
  • 6
  • Same solution worked for me with a dictionary. Initialising it directly caused a forever running indexing. Initialising it in `init()` step by step does work perfectly. Worth to mention that I had to delete the `.xcworkspace` file too. – jboi Dec 22 '14 at 14:10
  • Fixed it for me with no dictionaries involved. Just an array of tuples which was fine with 8 elements in the declaration. Had to revert to appends with 11 elements. Didn't bother to find the exact breaking point but builds 10x faster. Xcode version 6.1.1 (6A2008a) on Mavericks. – Josh Jan 03 '15 at 17:22
  • I hit the issue with exactly 6 elements as well. 5 was fine. – Justin Lau Jan 22 '15 at 08:25
  • Is this an XCode problem or a compiler problem? – Sljux Mar 03 '15 at 12:36
  • Thanks for the sleuthing here. It's a pretty frustrating bug and it persists well into production builds. I'm using Xcode 6.3.1 on Yosemite. – Matt Long May 04 '15 at 03:23
  • This makes me wonder whether static constants/vars/methods generally make Xcode slower to index? I have several in my current project and indexing is very slow. – BadmintonCat May 27 '15 at 03:59
  • When my xcode started to index forever, I have no idea it is due to my own code until I found this... thank you!! It also heats up my Macbook until I have to shut it down, scary stuff – Bruce Jul 13 '15 at 01:06
  • there are only a few things i really get pissed off at apple for, and this is one – tango whiskey double Oct 13 '15 at 22:17
  • Still persists on Xcode 6.4. This solution worked but required restarting xcode a few times. Possibly deleting the .xcworspace file as jboi suggested may have done the trick quicker. – WaterNotWords Oct 30 '15 at 03:12
  • Worked for me on XCode 7. Deleting DerivedData folder was also required. – redent84 Nov 10 '15 at 17:00
  • On Xcode 7.2 the line that was causing me trouble was this `class func downloadCulture(culture: Culture, progress: ((done: Int, total: Int)->(Void))?, completion: (result: Int)->(Void))` Simply the declaration of the function – Gonzo Dec 13 '15 at 02:24
  • 4
    I experienced this in Xcode 7.3 with an array literal of 229 items. Instead of breaking it up, I added a type declaration instead of letting Swift infer the type. After I did that, it worked. – Brigham Apr 12 '16 at 14:24
  • Did you open a radar for this? if so whats the #? – cynistersix Jul 21 '16 at 22:34
34

The only working solution for me is to delete all the derived data (not only for the current project, just clean up the whole folder) and then restart Xcode.

  1. Open File / Preferences in Xcode

  2. Click on Locations on the far right of the pop up window

  3. Click on the little arrow icon next to "/Users/Mac/Library/Developer/Xcode/DerivedData"....it takes you to an Xcode folder that contains a DerivedData folder (that contains all of the derived data from your previous projects.)

  4. DELETE the DerivedData folder

patricus
  • 48,843
  • 11
  • 119
  • 125
Remy Cilia
  • 2,353
  • 18
  • 30
  • 1
    @TravisM. Did you follow the steps? If you go to Window, Organizer, Projects, Delete Derived Data, it won't work. You need to go through Preferences. – ericgu Apr 01 '15 at 21:08
  • @ericgu Yeah, but it didn't work. I did fix my issue, though, it was related to me initializing a dictionary with hardcoded data in one shot. When I moved the code to add the hardcoded data one row at a time, the freezing / slow issues disappeared immediately. – Travis M. Apr 01 '15 at 21:58
  • Folder at ~/Library/Developer/Xcode/DerivedData/ on my machine. You can also find it by going to Window > Projects in Xcode. – Suragch Apr 23 '16 at 02:39
  • Thanks. This helps. The "forever indexing" problem starts right after i updated my cocoaPod version and executed a pod install. – WKL Jun 14 '16 at 03:05
11

Are you using CocoaPods? I ran across the same issue earlier today. (Using xCode 6.1.1)

To fix the issue, I deleted everything in ~/Library/Developer/Xcode/DerivedData, the Pods folder in my project directory, and <project>.xcworkspace.

I then opened terminal, navigated to my project directory, and ran pod install again.

Michael Schinis
  • 697
  • 1
  • 7
  • 21
  • 1
    Yes I do. For now the Xcode is behaving ok. But it still from time to time gives sourcekit crash error. My solution is to delete the derived data folder. – leonard Jan 05 '15 at 16:00
  • Glad to see that this worked for someone else too :). Seems like xCode is trying to index CocoaPod Libraries and gets stuck somewhere. – Michael Schinis Mar 18 '15 at 12:40
  • 1
    Deleting the Pods folder and .xcworkspace file, and then running pod install again worked. – KML Nov 15 '15 at 10:05
9

Had the same issue today. Xcode 6.3.2, medium-sized Swift project. At one point it started indexing and it would never finish indexing. The code that caused this was a dictionary of type [String:[String]], so a string-key dict with string arrays as values. I had two of these with keys from A to Z and each of these 26 entries contain a string array with 5 to 10 strings.

Clearing derived data didn't help. Only commenting out those dicts made it go again.

Honestly, this is ridiculous! Apple needs to fix Xcode! It's already horribly slow when compiling Swift projects but bugs like this are a showstopper. I can't do my job properly with this!

BadmintonCat
  • 9,002
  • 10
  • 64
  • 114
6

For those still having this issue, this is a workaround I've come to enjoy which prevents you from having to enter the objects one by one:

// instead of this, which freezes indexing
let keys = [keyQ, keyW, keyE, keyR, keyT, keyY, ... keyM]    

// and instead of this, which is ugly & lengthy
var keys = [KeyboardKey]()
keys.append(keyQ)
keys.append(keyW)
...
keys.append(keyM)

// use this:
var keys = [KeyboardKey]()
keys.appendContentsOf([keyQ, keyW, keyE, keyR, keyT, keyY, ... keyM])
Andrew Robinson
  • 3,295
  • 2
  • 18
  • 26
  • 1
    Wow... I had the exact same issue. Thanks! I reported it as a bug to Apple. Doing what you said didn't work for me. I had to break up my long array in to smaller arrays each with five or less elements. – ma11hew28 Dec 15 '16 at 18:22
5

For me, I tried all the above with no success; but all I had to do was to delete the derived data folder, then open up another random project, wait for it to index and now my original (malfunctioning) project works!

Do the development world a favour apple and make your swift compilers open source- so we are not all thwarted by your incompetence.

Gmeister4
  • 744
  • 9
  • 19
3

I am using Xcode Version 7.3 (7D175)

I think I might have figured out an underlying problem. There where two instances where I got stuck in the indexing phase:

  • I created a closure that I assigned to a variable and omitted the type signature. I think xcode had issues with that type inference step. If I remember correctly one of the arguments was a CGPoint, which has an overloaded constructor. My hypothesis is that there where too many possibilities of what my closure might accept as arguments.

  • I refactored a factory method such that instead of returning instances of one type, it could return instances of many types with a common base class. It appears that wherever I used the factory method, I had to cast the resulting object to a specific type (either with as? or by assigning it to a variable that accepts a specific type) Again the type inference step seems to be broken.

It seems like the same is going on with the dictionary declarations mentioned by earlier individuals. I filed a bug report with apple.

DudeOnRock
  • 3,066
  • 3
  • 23
  • 51
2

I experienced this same issue after upgrading to 6.1. Xcode would get stuck compiling or indexing without generating a specific error message.

The issue was finally resolved by breaking some of the longer expressions in the swift files down into multiple shorter expressions. Part of my program combines many different string variables to form a longer string. Attempts to combine them in a single expression and using the addition assignment operator both failed. I was able to make it work by doing something similar to the following (simplified):

var a = "Hello"
var b = " "
var c = "World"
var d = "!"
var partA = a + b
var partB = c + d
var result = partA + partB

I got this idea from receiving the following error many times in the previous Xcode version "Expression was too complex to be solved in reasonable time; consider breaking up the expression into distinct sub-expressions."

Hope this helps

Adam137
  • 63
  • 6
  • Yes thanks, I actually took this kind of suggestions. And I also shrank the length of one of my files from 1500 lines to about 1200. And of course I created a new project and imported all the files one by one to it. Then finally it gets back on. Not really sure which one is the ultimate saviour. – leonard Oct 23 '14 at 12:49
  • Splitting up a long expression in Swift did the trick for me. – MandisaW Mar 18 '16 at 20:24
2

I've struggled with the same problem. I've tried the two solutions mentioned ( deleting derived data and deleting .xcworkspace ) with no success. I also tried slowly commenting out most of the code bit by bit and removing the files until there was almost nothing left and the indexing was still stuck.

I did find a solution that worked for me, I've opened the project with an older Xcode Version 6.1 (6A1030) which had no problem indexing then got back to the latest Xcode Version 6.1 (6A1052d) which I was using before and indexing was fixed and continued to work well.

My conclusion is that this is a bug with Xcode Version 6.1 (6A1052d) which I hope will improve with future releases.

The problem does come back once in a while, the same fix works each time. I guess another solution would be to just stick with the older Xcode Version 6.1 (6A1030) but it won't work with devices running iOS 8.1 and it won't have the latest bug fixes.

Jorge Costa
  • 141
  • 1
  • 3
  • I have tried most of the suggestions around for solving the perpetual indexing issue and this was the only one that worked for me. I didn't have an older Xcode 6 but I had Xcode 5. It would not build, but it did index and after that Xcode 6.1 indexed successfully. – SarahR Nov 08 '14 at 02:23
  • I forget to mention that this was only a temporary solution and I had to do it again a few hours later. – SarahR Nov 08 '14 at 02:24
2

On my Xcode the solution was to close all redundant windows. For some reason many open windows make Xcode very slow.

pkamb
  • 26,648
  • 20
  • 124
  • 157
Arik Halperin
  • 358
  • 3
  • 8
  • for me this was the solution as well, surprising as it worked well for a long time before with the same number of open windows – Christian Jan 07 '16 at 09:27
2

I have tried this with Xcode 8.3.3. Here are my results:

You can write perfectly fine Swift code that will cause indexing to hang.

Once indexing hangs, it hangs. Changing the Swift code back to something that wouldn't cause indexing to hang doesn't help, it still hangs.

Closing the project and reopening doesn't help in that situation.

Quitting Xcode and restarting it helps. Indexing will not hang anymore (that is if you changed the code back to something that doesn't make it hang).

Restarting your Mac helps as well, although it isn't needed.

The hanging is caused by perfectly fine Swift code. An example that I had looked like

if let date = function1()
?? function2()
?? function3()
?? function4()
?? function5()
?? function6()
?? function7()
?? function8()
?? function9()
?? function10() {
    return date
}

Indexing would hang. I commented out most of the "??" lines and it was fine (after quitting and relaunching Xcode). Uncommented one line after the other. With some number of lines it was fine, then uncommenting the next line would make it hang.

The only thing that helps apparently is changing your code.

gnasher729
  • 47,695
  • 5
  • 65
  • 91
2

Xcode 11.5 (11E608c) and still the same issues, 6 years after the original question. I wish i could "mark" apple in this question so they can see this mess. This is a large project( >1000 files) and i was under the clock so when i notice the freezing index i was with more than 100 files changed and can't go back.

I've tried everything:

  1. clear Derived data and build
  2. Restart xcode , restart mac
  3. remove and add source
  4. Searched for dictionaries literal's etc etc

The problem was an array creation:

private var overlayColors: [UIColor] = [UIColor(hex: "#b71c1c"), UIColor(hex: "#4a148c"),
                                        UIColor(hex: "#880e4f"), UIColor(hex: "#1de9b6"),
                                        UIColor(hex: "#f50057"), UIColor(hex: "#311b92"),
                                        UIColor(hex: "#f44336"), UIColor(hex: "#651fff"),
                                        UIColor(hex: "#d500f9"), UIColor(hex: "#3d5afe"),
                                        UIColor(hex: "#bf360c"), UIColor(hex: "#0d47a1"),
                                        UIColor(hex: "#006064"), UIColor(hex: "#2979ff"),
                                        UIColor(hex: "#ff6f00"), UIColor(hex: "#1a237e"),
                                        UIColor(hex: "#795548"), UIColor(hex: "#004d40"),
                                        UIColor(hex: "#00e676"), UIColor(hex: "#01579b"),
                                        UIColor(hex: "#33691e"), UIColor(hex: "#827717"),
                                        UIColor(hex: "#76ff03"), UIColor(hex: "#ffc400"),
                                        UIColor(hex: "#e65100"), UIColor(hex: "#00b0ff"),
                                        UIColor(hex: "#ff3d00"), UIColor(hex: "#616161"),
                                        UIColor(hex: "#263238"), UIColor(hex: "#ff1744")]

What helped me to discover the bad swift file was when xcode freezed indexing i did the following steps

  1. open activity monitor -> "swift" process ->show process info -> open Files and Ports. This will give you a list of what files this process is running drilling down your list of possible bad files
  2. Other handy tool is this script SOURCEKIT_LOGGING=3 /Applications/Xcode.app/Contents/MacOS/Xcode &> ~/Documents/xcode.log this will start Xcode with level 3 verbose and start logging in the log file.
  3. Search in the log file the last entries for your swift files ex: "my_project/Source/App/"

It's not a full solution but it's helpful to drill down and know where to look.

open activity monitor -> "swift" process ->show process info -> open Files and Ports.

firetrap
  • 1,760
  • 2
  • 22
  • 37
1

Finally, I "solved" the issue, though it is just a workaround.

I created another project and added files one by one to it. Then I spotted a "very long" viewcontroller.swift file. Then I broke its codes into modules and made those repeatedly used codes into functions in another swift file. And also, I took the suggestion online that long expression should be broken into shorter ones. Then, the indexing works and the compiling works.

So for now, I have it "solved".

BUT, I don't think this is right. Xcode IDE should be more than capable of handling my "very long" swift file, only 1500 lines. I believe this is definitely a bug (existing for a long time), although Xcode 6.1 is already an upgrade from Xcode 6.0.1.

leonard
  • 2,237
  • 4
  • 17
  • 26
1

For me, I deleted the Xcode app and downloaded it again and install it. That solved the issue, at least over now.

Tzegenos
  • 765
  • 11
  • 15
1

Xcode indexing usually for your code for suggestions and auto complete among other things like helping you in story boards and vice versa. But to make faster your xcode project you can turn it off/on via terminal

Turn off indexing
defaults write com.apple.dt.XCode IDEIndexDisable 1 Turn on indexing defaults write com.apple.dt.XCode IDEIndexDisable 0

But Better approach to use a speedy mac with good RAM.

B25Dec
  • 2,065
  • 3
  • 29
  • 50
  • 2
    Turning off indexing severely cripples Xcode and should not be done. Telling somebody to purchase a new Mac should never be the answer, a 2 year old laptop should be able to handle the latest Xcode. – Knight0fDragon Jan 05 '17 at 02:08
  • macOS 10.13 Beta 7 introduced something that crashes both Xcode 9 Beta 6 and Xcode 8 as soon as the indexer runs. Turning it off was the only way to continue using Xcode, even with a crippled version. – Pegolon Aug 22 '17 at 10:10
0

I've had this issue as well and solved it by removing/changing expressions with the "+" operator.

I changed this:

var mainArray = arrayOne + arrayTwo + arrayThree + arrayFour + arrayFive

To this:

var mainArray = arrayOne
mainArray += arrayTwo
mainArray += arrayThree
mainArray += arrayFour
mainArray += arrayFive

It solved the problem.

My machine is a maxed out MBP late 2013

Nilanshu Jaiswal
  • 1,265
  • 3
  • 15
  • 31
  • Exactly my experience. It hangs with perfectly fine Swift code, and the only way to fix it is to change the code. – gnasher729 Jul 03 '17 at 13:17
0

The Xcode 6.2 beta resolved the issue for me. Not lightning-fast, but at least it isn't indexing forever. The beta does not install over the top of your regular Xcode installation, so if you don't like the beta, you can just delete it.

Various Xcode downloads including the beta >

Nilanshu Jaiswal
  • 1,265
  • 3
  • 15
  • 31
Warren Whipple
  • 1,050
  • 1
  • 9
  • 17
0

You may wish to update to Xcode 6.1.1

It has been officially released and resolved for us the indexing problem. In the update description, it says that they have applied stability fixes so it is very likely that it will behave in a more stable fashion.

Nilanshu Jaiswal
  • 1,265
  • 3
  • 15
  • 31
Angel Naydenov
  • 1,355
  • 1
  • 11
  • 13
  • 7
    Interesting. For me, 6.1.1 _introduced_ the endless indexing problem, with a project that was opening fine in 6.1. *sign* – Pascal Bourque Dec 04 '14 at 14:05
  • I see. In our case we also simplified expressions and reduced class sizes using extension classes. Which is pretty much ridiculous that we had to do it but it is what we had to do. And it seems to be doing the trick for now. Also by commenting out lines we narrowed what piece of the code actually is "overly complex" as per what Swift compiler thinks and reduced complexity as much as possible. Hope they are going to fix this soon as it is pretty annoying. – Angel Naydenov Dec 13 '14 at 15:29
0

If you don't mind reverting back to 6.0.1 until they figure it out, that's what worked for me. I was having the same issue with both 6.1 and 6.1.1. Now I'm good. I'll try 6.2 when it comes out.

You can find previous versions of apple software on their official dev site, here: https://developer.apple.com/downloads/index.action

If you do this, make sure to delete your current copy of Xcode first.

0

I am using Xcode 6.1.1 with swift files on the same exact MacBook Pro.

As I kept adding rows into a 3D string array, Xcode all of sudden became unusable and now I can't do anything.

Will try to revert to 6.1 and hopefully the problem will go away.

  • I have the same issue. After adding an array of dictionaries xcode became unusable ... Did you find solution? – Almazini Feb 21 '15 at 07:46
  • I went back to Xcode 6.1 which worked better. It didn't get stuck on indexing forever, but sometimes i would type and get the beach ball for 4 seconds. Overall I was able to code enough to get stuff done. I didn't change any of my code. Though on Xcode 6.1 the battery of macbook pro didnt seem too affected, but on my macbook air mid 2013 running 6.1.1, the battery life is absolutely shot. It goes from ~12 hours to 2 hours remain once i start Xcode. – gardner888 Feb 22 '15 at 14:32
0

I am seeing this in Xcode 6.3.2. I had really hoped that a year after release, they would have the compiler working, but alas.

If none of the above solutions work for, try checking your code for syntactic errors. In the process of refactoring, I extracted a closure but forgot to qualify the parameters:

    let hangsInsteadOfError = { l, r in
        return l.nameFirst < r.nameFirst
        || l.nameFirst == r.nameFirst && l.nameLast < r.nameLast }

    let fixingErrorAvoidsHang = { (l:User, r:User) -> Bool in
        return l.nameFirst < r.nameFirst
            || l.nameFirst == r.nameFirst && l.nameLast < r.nameLast }

If I have learned anything from working in Swift, it is to work incrementally, to avoid having to backtrack too much to find the offending code.

Chris Conover
  • 8,161
  • 5
  • 47
  • 65
0
  1. Is your indexing status an "Indicator circle" or "Progress bar"?
  2. If it is an "Indicator circle", that means it already stuck at the beginning.
  3. Open and check with your other projects, if they are all the same, that means it's a system issue.
  4. Just restart your computer and everything will be fine.
Nilanshu Jaiswal
  • 1,265
  • 3
  • 15
  • 31
Weidian Huang
  • 1,960
  • 1
  • 16
  • 23
0

I use Xcode 8.2 and also ended in this problem. It started after I defined a complex tuple variable -- an array of tuple with subarray of tuple. Things get really slow when the subarray of tuple has a property that is programmatically calculated.

As some other answers noted, the indexing takes forever, and I believe it is trying to infer the types the variable.

I solved the problem first by clearly define the variable with types included. When updating the property, I calculate it first then assign it to the tuple, instead of calculating in defining the variable.

Here is an example code.

var sectionTuples: [(section: String, rows: [(name: String, subtitle: String)])] = []
let subtitle1: String = "" // something calculated dynamically
let subtitle2: String = "" // something calculated dynamically
sectionTuples = [(
section: "Section 1", rows: [
(name: "name1", subtitle: subtitle1),
(name: "name2", subtitle: subtitle2)
])]

The bottom line is that don't let Xcode infer complex structures.

Nilanshu Jaiswal
  • 1,265
  • 3
  • 15
  • 31
Q Liu
  • 677
  • 1
  • 5
  • 7
0

I was having the same issue. My Xcode is 8.2.1. But in my case, I wanted to create an array of dictionary with 33 key-value pairs. I was doing in the following way which was stuck in indexing:

var parameter = [String : AnyObject]()
var finalArray = [parameter]

for item in listArray
{
    parameter = ["A": item.a as AnyObject, "B": item.b as AnyObject, "C": item.c as AnyObject, ... , "Z": item.z as AnyObject]

    finalArray.append(parameter)
}

Following worked for me:

var parameter = [String: AnyObject]()
var finalArray = [parameter]

for item in listArray
{
    parameter["A"] = listArray.a as AnyObject
    parameter["B"] = listArray.b as AnyObject
    parameter["C"] = listArray.c as AnyObject
    parameter["D"] = listArray.d as AnyObject 
    .
    .
    .
    parameter["Z"] = listArray.z as AnyObject 
    finalArray.append(parameter)
}
Nilanshu Jaiswal
  • 1,265
  • 3
  • 15
  • 31
Trup
  • 623
  • 5
  • 17
0

I had expressions like:

let x = (value as? Int) ?? someDefault

also

guard let x = (dateFormatter().string(from: Date()) + msg + "\n").addingPercentEncoding(...) else { ... }

So the point is to rewrite your file to contain only kindergarten level expressions and the indexing problem will go away.

soger
  • 927
  • 7
  • 18