Xcode swift indexing forever

XcodeIndexingSwift

Xcode Problem Overview


I'm currently developing an iOS app using swift and Xcode 6 (Beta 3).

Everything went fine so far but now as my project grows, Xcode suddenly began indexing and it does that again and again, making Xcode nearly unusable.

I have searched the web for similar problems and tried the solutions but none of them did help. Even disabling the indexing process (defaults write com.apple.dt.Xcode IDEIndexDisable 1) does not stop Xcode to do that.

While indexing, my CPU usage goes up to 300%+, causing the fans to run at highest speed.

In Activity Monitor there are several tasks named "swift" taking up about 1GB memory each.

Xcode Solutions


Solution 1 - Xcode

Killing the processes named 'swift' and then checking the error in xcode will give you the part of the code giving you trouble. There are some bugs in swift that needs to be circumvented.

To kill the process: Applications > Utilities > Activity Monitor. Then find the "swift" process, double click and choose Quit or Force Quit.

Solution 2 - Xcode

Happened to me with Xcode 7.3

Had to clean everything Xcode had cached to solve it.

Solution:

rm -frd ~/Library/Developer/Xcode/DerivedData/*

rm -frd ~/Library/Caches/com.apple.dt.Xcode/*

Solution 3 - Xcode

I had this same issue and it took me FOREVER to solve it. I'm pretty sure I've seen every question on the internet about this issue and I tried all of the solutions. Turns out all I had to do was....

Restart my computer

Solution 4 - Xcode

Solved it: I deleted the most recently added files from the project and the problem disappeared. Then I started to add back the files, one by one until the problem reappeared. So I found the file causing the problem. Then I deleted the most recently added code from that file and again, the problem disappeared.

That way, I found a piece of code which was responsible for that behavior.

Solution 5 - Xcode

I had the same issue in my code. The solution for me was delete all spaces in the array in my code.

Ex.

  struct Objects {

  let objectA = ["text1", 
                 "text2", 
                 "text3", 
                 "text4"] }

// Noise, CPU 100% and Index forever. The solution is...

struct Objects {
    let objectA = ["text1","text2","text3","text4"]}

// Solved making the Array or String with no space.

Solution 6 - Xcode

I had that problem when I was at the swift crunch in krakow a couple weeks ago. We had the code on github, experienced that indexing problem on a macbook, we tried pulling the repo on 2 other macbooks, same result.

It's clearly a bug, I don't know what is causing it, we tried whatever we could think of (clean, clean build folder, manually removing files not in the repo, rebooting, killing processes, etc.), and after a couple hours the only thing left to do was creating a new xcode project from scratch and manually importing the files from the other project.

Never happened again since then, neither on that nor on other projects.

Solution 7 - Xcode

For me, I made a stupid mistake. I write a Class like this:

class A: A {
.......
}

A class inherit itself that causes the freezing. There is no message hint from Xcode. You can just take this as possible reason ~ .

Solution 8 - Xcode

It's Xcode bug. Problem caused with concatenation in one line:

var value = "some text" // it can be String or Array
value = value + value1 + value2 + value3 + value4 + value5 + value6 // etc

This correction fixes this bug:

var value = "some text"
value += value1
value += value2
value += value3
value += value4
value += value5
value += value6

Solution 9 - Xcode

I was creating a dictionary like this

var dic1 = [
    "isDestination" : self.isDestination ?? false,
    "price" : self.price ?? ""
]

and self.price is of type Int and I was giving its fallback value as an empty string which screwed up the Xcode compilation.

Solution 10 - Xcode

I got this issue and 6 hours later (after trying everithing and build new project again step by step copying resources) I FOUND MY PROBLEM:

class A : A {
...
}

By the fact of copy/paste I had a class that extends itself, and this makes indexing crazy.

Solution 11 - Xcode

It's definitely a Xcode bug and I reported that to Apple. When you have a large dictionary literal or a nested dictionary literal. You have to break your dictionary to smaller parts and add them with append method until they fix the bug. Xcode 8.2.1 (8C1002)

Solution 12 - Xcode

I had the same problem with one call adding 11 NSLayoutConstraint objects to an array.

The solution was to divide the code into several calls, each adding only 3 objects to the array. Weird.

That was in Xcode 6.4

Solution 13 - Xcode

Too many string concatenations in one line cause troubles. Helped me too. Originally was pointed by Zhenshan Yu there: https://stackoverflow.com/questions/24310246/xcode-6-beta-not-compiling

Solution 14 - Xcode

I had this issue with XCode 6.3 when creating a C++ project. Before switching over to developing in SubLime, my last ditch effort was to delete the XCode app and reinstall. It was a long process, but my version of XCode is now updated to 7.3 and everything is working as it should.

So if nothing else seems to be working, you could try deleting XCode from your applications folder and then reinstalling. Just be sure you aren't deleting any project files you want to keep.

Solution 15 - Xcode

My particular problem was a fairly long literal dictionary containing much data.

My solution was to understand that Xcode indexing wasn't "stuck", but just taking a long time.

So I only had to wait more time than I expected.

Solution 16 - Xcode

Mine was about dragging a new file with String extension to the project and not adding it to all required targets. Hope that helps someone.

Solution 17 - Xcode

Backup your project delete the lastone and restart the xcode simple :-)

Solution 18 - Xcode

I too faced the same issue for Xcode 9.1. So i looked into Activity Monitor. There was swift process which was above 100%. Double Clicked it and Quit. Done. Now its working fine.

Solution 19 - Xcode

I went to tools->task and contexts->clear contexts and that seemed to give the computer rest finally!

Solution 20 - Xcode

enter image description here

I got this issue when my Xcode was 9.2 . First I deleted xcworkspace file ,cleaned and built according to the others' answer.But it did not work. Then I updated Xcode to 9.3 It also did not work. I checked my code and found that the recently written code made Xcode Indexing forever:

TimeInterval(3600*24*(-randomDay))

Then I amended it:

TimeInterval(-3600*24*randomDay)

It worked. I find that many situations can cause Xcode to work abnormally.So I think the correct solution is that think about what you've done for your project recently

Solution 21 - Xcode

In my case the issue was caused by some aritmetic sums. I was creating a collectionView with all the different frames programmatically doing it like this:

cell.textView.frame = CGRectMake(8 + 10 + 12, 0, 150 + 6 + 6 + 4, 50)

I just changed it to:

cell.textView.frame = CGRectMake(30, 0, 166, 50)

It helps me figure out the margins and paddings more easily, but just puting the result of the sum changed the build speed from 5 - 7 minutes to 20 seconds or so.

Solution 22 - Xcode

Yet one possible thing, that may cause such behavior: For debugging purpose I changed system time, set up in one week ago - and I've got infinite indexing. As soon, as I set time back - indexing has stopped.

Solution 23 - Xcode

in my case i had the emulator open with an app builded with previous files. Just close de emulator

Solution 24 - Xcode

I've tried all the things listed, indexing is keep freezing. This helped me: If your indexing is freeze, and you have one or more swift process eating 99% of your cpu - just kill this swift task(s), wait a bit, and progress should move. It can repeats, until it reaches finish, in my case I killed the process 7 times, but at the end, indexing was completed!

Solution 25 - Xcode

For me it was circular inheritance causing the issue:

class CustomButton: CustomButton {
    ...
}

And various other recent find/replace errors in the code. Xcode wasn't highlighting them as errors and just kept indexing.

Solution 26 - Xcode

I recognized today, that running Apples Playgrounds application alongside Xcode I have that very same symptoms. and maybe that was the root cause in earlier situations. So in my case, closing Playgrounds did the trick.

Solution 27 - Xcode

Non of the answers helped in my case. I tried multiple things like:

Device and Simulators - Wifi connected device

Disconnect all devices which can be connected with wirelessly.

Removing Xcode's cache, derived data:

rm -frd ~/Library/Developer/Xcode/DerivedData/*
rm -frd ~/Library/Caches/com.apple.dt.Xcode/*

Deleting defaults for Xcode

defaults delete com.apple.dt.Xcode

Solution

What helped in my case was to rename project folder. Once I did that everything started working again.

Solution 28 - Xcode

In my case, I tried all the suggestions I found on the internet but nothing worked.

The solution that worked for me was to run another project on xcode that could be indexed, and once indexing was done I closed xcode and opened it on the first project that had indexing issues, and it works.

No idea why, but it works :)

Solution 29 - Xcode

This is a workaround I posted on another stackoverflow thread related to Xcode indexing problem. This question looks to be more swift related but my workaround can probably be useful here too. So here it is. My project is very big (merging objective c, c++, swift, and java files with j2obj) and none of the answers here solved the indexing problem. The idea is to limit the CPU usage of the Xcode indexing process with an external tool like cputhrottle.

So first you need to install cputhrottle in terminal

> brew install cputhrottle

Then limit the Xcode indexing process like this (20 = 20%)

> sudo cputhrottle $(pgrep -f com.apple.dt.SKAgent) 20

I've exposed my "solution" here with more details : How to prevent Xcode using 100% of CPU when indexing big projects

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
QuestionzisoftView Question on Stackoverflow
Solution 1 - XcodehannesrView Answer on Stackoverflow
Solution 2 - XcodeFawkesView Answer on Stackoverflow
Solution 3 - XcodeAlexView Answer on Stackoverflow
Solution 4 - XcodezisoftView Answer on Stackoverflow
Solution 5 - XcodeMaximo LucosiView Answer on Stackoverflow
Solution 6 - XcodeAntonioView Answer on Stackoverflow
Solution 7 - XcodeVictor ChoyView Answer on Stackoverflow
Solution 8 - XcodeIgorView Answer on Stackoverflow
Solution 9 - XcodeRajat TalwarView Answer on Stackoverflow
Solution 10 - XcodeSendelDLView Answer on Stackoverflow
Solution 11 - XcodeSaeed IrView Answer on Stackoverflow
Solution 12 - XcodeOliver EichhornView Answer on Stackoverflow
Solution 13 - XcodeMikhail LarionovView Answer on Stackoverflow
Solution 14 - XcodeTMCView Answer on Stackoverflow
Solution 15 - XcodeJacobo KoenigView Answer on Stackoverflow
Solution 16 - XcodenikansView Answer on Stackoverflow
Solution 17 - XcodeShakeel AhmedView Answer on Stackoverflow
Solution 18 - XcodeJoel Vivek LeoView Answer on Stackoverflow
Solution 19 - XcodeGabriel BabrielView Answer on Stackoverflow
Solution 20 - XcodeMartinWoView Answer on Stackoverflow
Solution 21 - XcodeYlunaView Answer on Stackoverflow
Solution 22 - Xcodeuser3567929View Answer on Stackoverflow
Solution 23 - XcodeDavid RearteView Answer on Stackoverflow
Solution 24 - XcodeDavid KyslenkoView Answer on Stackoverflow
Solution 25 - XcodeCharlie SeligmanView Answer on Stackoverflow
Solution 26 - Xcodeedsa-steffenView Answer on Stackoverflow
Solution 27 - XcodeMarek StaňaView Answer on Stackoverflow
Solution 28 - XcodeEL OUFIR HatimView Answer on Stackoverflow
Solution 29 - XcodejptsetungView Answer on Stackoverflow