zisoft
zisoft

Reputation: 23078

Xcode swift indexing forever

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.

Upvotes: 66

Views: 56766

Answers (29)

EL OUFIR Hatim
EL OUFIR Hatim

Reputation: 419

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

Upvotes: 0

Marek Staňa
Marek Staňa

Reputation: 564

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.

Upvotes: 1

Jacobo Koenig
Jacobo Koenig

Reputation: 12534

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.

Upvotes: 0

Rajat Talwar
Rajat Talwar

Reputation: 11912

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.

Upvotes: 3

Igor
Igor

Reputation: 12303

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

Upvotes: 4

edsa-steffen
edsa-steffen

Reputation: 179

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.

Upvotes: 0

Charlie S
Charlie S

Reputation: 4604

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.

Upvotes: 0

hannesr
hannesr

Reputation: 459

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.

Upvotes: 27

David
David

Reputation: 889

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!

Upvotes: 0

David Rearte
David Rearte

Reputation: 874

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

Upvotes: 0

user3567929
user3567929

Reputation: 107

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.

Upvotes: 0

Yluna
Yluna

Reputation: 103

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.

Upvotes: 0

jptsetung
jptsetung

Reputation: 9157

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

Upvotes: -1

MartinWo
MartinWo

Reputation: 11

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

Upvotes: 0

Gabriel Babriel
Gabriel Babriel

Reputation: 1

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

Upvotes: 0

Joel Vivek Leo
Joel Vivek Leo

Reputation: 1

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.

Upvotes: 0

Shakeel Ahmed
Shakeel Ahmed

Reputation: 6021

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

Upvotes: 0

Maximo Lucosi
Maximo Lucosi

Reputation: 388

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.

Upvotes: 10

nikans
nikans

Reputation: 2565

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.

Upvotes: 0

Saeed Ir
Saeed Ir

Reputation: 2332

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)

Upvotes: 2

SendelDL
SendelDL

Reputation: 39

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.

Upvotes: 2

Victor Choy
Victor Choy

Reputation: 4256

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

Upvotes: 4

Fawkes
Fawkes

Reputation: 3961

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/*

Upvotes: 22

TMC
TMC

Reputation: 13

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.

Upvotes: 0

Alex
Alex

Reputation: 319

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

Upvotes: 18

Oliver Eichhorn
Oliver Eichhorn

Reputation: 307

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

Upvotes: 1

zisoft
zisoft

Reputation: 23078

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.

Upvotes: 13

Mikhail Larionov
Mikhail Larionov

Reputation: 684

Too many string concatenations in one line cause troubles. Helped me too. Originally was pointed by Zhenshan Yu there: Xcode 6 Beta not compiling

Upvotes: 0

Antonio
Antonio

Reputation: 72780

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.

Upvotes: 4

Related Questions