Xcode 9 keeps indexing at 100% of CPU [duplicate] - xcode

A project I've been working for 2 months stopped working for no reason because Xcode got stucked on "Indexing". I can't Build the project anymore. If I try to build, Xcode freezes and I have to force quit. This happens only with this project.
I tried cleaning all derived data but didn't help.
I'm using Xcode 4.5.2.
Any ideas?

Open your Project Folder.
Find ProjectName.xcodeproj file.
Right-Click Copy and Paste to Safe Place.
Right-Click Show Package Contents.
Find project.xcworkspace file and delete that file.
Reopen Your Project and clean and Rebuild.
If your problem is not solved then replace the file with your backup file.

Close that project from Xcode
Open Xcode Organizer, find the problematic project
Delete Derived Data folder in the Organizer
Close/re-open Xcode
Nuking Derived Data is the first thing to try in all cases of Xcode misbehaving

I had this exact problem, it was caused by a 20 item array literal. Had to switch to different syntax. Pretty silly.

Close any opened Xcode
rm -rf ~/Library/Developer/Xcode/DerivedData
Right click your PROJECT_NAME.xcworkspace, choose 'show content', and delete 'xcuserdata' folder

Another thing to try if your trying to solve indexing issues and you're this far down the page!
Try adding this flag to your build settings.
-Xfrontend -warn-long-expression-type-checking=400
It will cause warning where the compiler take a long time to deduce a complex expression.
This may cause a build error which will go away after you find the slow expressions and then remove the build flag.

I had a similar problem, and found that I accidentally defined a class as its own subclass. I got no warning or error for this but the compiling got stuck.
class mainClass : mainClass
{
...
}

When using Xcode 6 and it says
Waiting for make
It might be that an instance of make is already running. Kill the process and indexing proceeds. Silly, but worked for me.

This happened to me. If you are using cocoapods do this:
Delete project.xcworkspace
Reinstall pods using pod install on the terminal
It will create a new project.xcworkspace
Open the new project.xcworkspace
-> Clean
-> Build

First, disconnect from network. Both your wired network and wireless network should turn off.
Second, kill the com.apple.dt.SourceKitService process. Then XCode would start to index again instead of stuck.

Hold alt > Product > Clean Build Folder

It's a Xcode bug (Xcode 8.2.1) and I've reported that to Apple, it will happen 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 Apple fixes the bug.

For me completely closing out of Xcode and then restarting the project worked.
This is not the solution for the original question, I don't believe, but it is one more simple thing to try before deleting files and folders, etc. Credit to this answer for the idea.

I had a similar problem where Xcode would spend lots of time indexing and would frequently hang building the project, at which point I had to force-quit and relaunch Xcode. It was very annoying.
Then I noticed a warning in the project about improperly assigning self as a delegate. Sure enough, there was a missing protocol in the class declaration. Note that there is a similar assignment in the OP's sample code (though it is impossible to tell from the sample whether the correct protocol is declared):
leaderboardController.leaderboardDelegate == self;
After resolving that warning (by correctly declaring the implemented protocol), Xcode stopped misbehaving. Also, I should note that the project did execute correctly since the protocol methods were implemented. It was just that Xcode could not confirm that the protocol should in fact implemented by the class.

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.

Nothing worked for me, my project is too big (merging objective c, c++, swift, and java files with j2obj). I've disabled Xcode indexing and worked without code completion for months (and it's a pain). But finally I've found a workaround. The idea is to keep Xcode indexing the code, but to limit its CPU usage 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 mode details : How to prevent Xcode using 100% of CPU when indexing big projects

I'm working with Xcode 11.4.1 and I have the same problem with several projects. Every time, when internet connection is lost, indexing gets up. The best solution (it's just my opinion based on observing this problem):
- turn off internet and just kill the "com.apple...." process, then restart the Xcode(turn on connection)
or more easier
- just restart the Mac(with the internet)

Had similar problem in Xcode 6.4. The progress bar indicated that "Indexing" was "Paused". Tried deleting project.xcworkspace, then deleting Derived Data as described above. Did not appear to help. Noting that the posts above also suggest fixing warnings, and since I had inherited this huge project with 180 warnings, I said to myself, "What the hell this looks like a good day to fix warnings". As I was fixing warnings, a half hour later, I noticed that the "Indexing" progress bar had increased from 10% to about 20%. An hour later, it was at 50%, then another hour to 80%, then after another half hour it was done! Conclusion: Add "take a long lunch or a nap" to the above suggestions.

I experienced the same issue for Xcode 7.0 beta.
In my case, values for "Provisioning Profile" and "Product bundle identifier" of "Build Settings" differed between PROJECT and TARGETS.
I set the same values for them. And I also used the same values for TARGETS of "appName" and "appNameTest".
Then closed the project and reopened it.
That resolved my case.

In my case, deleting the derived data directory did not help. Apparently I had a file locked by another process, because after closing out a couple of terminal windows and emacs, and terminating a react-native packager process, everything resolved.

I have experienced this problem in some projects with Xcode 9.3.1 and in my case the problem is due to some swift code that for some reason Xcode doesn't like. This problem is hard to solve because is difficult to find what file is causing the problem.
When I have this problem, I removing some files from the Xcode project (removing references) and I try to test if indexing works. My process to do so
Remove some files
Close Xcode
Open Xcode
If indexing finish try to rename some method if works probably the files you have removed they have something strange for Xcode.
In my case I had a class definition with a reactive extension in the same file and for some reason Xcode doesn't like it, I moved the reactive extension to another file and now the indexing works fine.

2022 | Algorithm what to do:
Open activity monitor and kill there com.apple.dt.SKAgent
If did not help:
Close Xcode(cmd+Q). Run command in terminal:
rm -rf ~/Library/Developer/Xcode/DerivedData
If did not help:
Restart PC
If did not help:
Right click your PROJECT_NAME.xcworkspace, choose 'show content', and delete 'xcuserdata' folder
If did not help:
run your project build with additional warning. For doing this you need to write:
-Xfrontend -warn-long-expression-type-checking=100
to the following place:
and optimize code at all of places.
If did not help:
Z. Uninstall XCode and install it from scratch
If did not help:
Z+1. answer of El Belga https://stackoverflow.com/a/50541767/4423545

Also stop running app. if you have another application running with your xcode, stop it first and you should have your indexing continue.

For me, the cause was I opened the same file in both the Primary Editor and Assistant Editor at the same time. Once I closed Assistant Editor, it came through. (Xcode Version 7.2.1)

Close Your Xcode , close any git client(source tree or terminal)if it is opened and finally restart your project.

Faced this recently on XCode 7.3.1 - for me, I noticed RAM usage going to 100% on to CleanMyMac3. The problem magically fixed itself after I restarted my machine. In all fairness however, I'd already gone ahead and tried the accepted-answer, so you'll want to do the same before you restart just in case :-)

I fixed this by simply deleting the app from my device and rebuild.

I had the same issue in swift 2.2
It had to do with a generic function overloaded function
func warnLog() {
print("Warning line: \(#line) file: \(#file) ")
}
func warnLog<T>(input:T? = nil) -> T? {
print("Warning line: \(#line) file: \(#file) ")
return input
}
func warnLog<T>(input:T) -> T {
print("Warning line: \(#line) file: \(#file) ")
return input
}
all I needed to do is remove one of the non used overloads
func warnLog<T>(input:T? = nil) -> T? {
print("Warning line: \(#line) file: \(#file) ")
return input
}

My case: it was not the project.xcworkspace file, it was not the Derived Data folder.
I've wasted a lot of time. Worse, no error message. No clue on the part of Xcode. Absolutely lost.
Finally this function (with more than 10 parameters) is responsible.
func animationFrames(level: Float,
image: String,
frame0: String,
frame1: String,
frame2: String,
frame3: String,
frame4: String,
frame5: String,
frame6: String,
frame7: String,
frame8: String,
frame9: String,
frame10: String) {
}
To go crazy! The truth is that it is worrisome (because there is no syntax error, or any type)

For XCode 9.3 indexing issue - Uninstall the XCode and instal again from zero. Works for me.

This issue happened to me when my machine was out of swap space. Closed several programs and browser tabs and the build suddenly succeeded after 30 minutes of being stuck in place. Nothing to do with derived data, locked files, etc. on my side.

Related

Could not read serialized diagnostics file: Invalid File: Invalid diagnostics signature

I'm getting this weird warning. I'm not sure what could cause it. A .dia file extension supposedly indicates a core digraph graphics file. I did not add one and the app has almost no ui at all.
Could not read serialized diagnostics file: error("Invalid diagnostics signature")
It appears to be an internal issue, the following steps seem to reliably resolve it for me.
Installing my uninstalled dependencies (ie: CocoaPods).
Cleaning the build folder.
Removing derived data.
Restarting Xcode
If that doesn't work restarting my computer makes this go away. 🤦
Here's the zsh script line I use (after navigating to the project's folder):
Note: Uses rm -rfs!
rm -rf ~/Library/Caches/CocoaPods; rm -rf Pods; rm -rf ~/Library/Developer/Xcode/DerivedData/*; pod install;
For me this issue occurred after I updated my Xcode to iOS15. The reason behind my issue was some of my swift packages were no longer up to date. Updating all my swift packages solved this issue. To do this simply do
File > Packages > Update to Latest Package Versions.
I also experienced this issue. The reason in my case was lack of storage space on my laptop so make sure to check that too.
Solution for M1 and M2 Macbook
I'm on a 2020 M1 Apple MacBook and none of these solutions worked for me.
The folder where I had the project created in was named 'Client Works' with a space in-between even throughout folder structure.
Previously folder structure: /Users/ABC/Documents/Client Works/AwesomeProject
Change folder structure to: /Users/ABC/Documents/Client_Works/AwesomeProject
Apparently that had an adverse effect on running the pod install properly. I renamed the folder to 'Client_Works' and ran pod install and everything started working.
Check the file and make sure all the document is linked to the project -> Target Memembership
If you're using a third party library, it might be where this warning or error originates. In my case, I had the same error, it was from a third party library not updated for Xcode 13. I had to go to the library on Github to check if they had an update for this error, and they had. Then, I updated the library's swift package. In my case I had to use the exact commit id at which they fixed the error.
I'm quite sure I know the issue and it is severe if you don't use version control. It happened to me twice with working on two different projects, when my disk space was around 7GB free with Xcode 13/13.1. I could not fix it manually, only removing all and cloning the repo again made it compilable again, and freeing disk space of course.
With Xcode 12 I had this issue around 4GB free space, but I could recover at least.
If you have pods in your project then make sure you are opening the .xcworkspace and not the .xcodeproj
When I removed a library from my Podfile I suddenly received a TON of these messages. The usual clean + clear derived data + restart trick unfortunately didn't seem to work for me this time.
Took me a while to figure this one out, but what did work was upgrading from Xcode 13 to Xcode 14. Doing so provided much better error messages! Turns out I needed to import Foundation, UIKit, or another framework in some of my files.

Build fails with "Command failed with a nonzero exit code"

When I try to build my app with Xcode, an error interrupts the build process:
Command CompileStoryboard failed with a nonzero exit code
Sometimes, it shows this error instead:
Command CompileSwift failed with a nonzero exit code
I have New Build System turned on.
What can I do to fix this?
Closing Xcode for me didn't have an effect. Instead, I cleaned the project using CommandShiftK.
I also found another reason: I had a storyboard reference to another storyboard which I had removed. The quick fix was deleting this.
I also facing same issue in xcode 10 and tried all the solutions provided but nothing working.
Then I deleted all the files and folders of the following folder :
~/Library/Developer/Xcode/DerivedData
and it worked like a charm.
When you stop building a project when the compiler is in the middle of something "important", this error could appear. In that case, building the project again and letting it finish normally makes this error disappear.
This is a known issue with Swift 4.2 and Xcode 10. I found an article here that fixed it for me: https://github.com/Yummypets/YPImagePicker/issues/236
In short, go to your projects build settings, and add a user defined setting named SWIFT_ENABLE_BATCH_MODE and set its value to NO.
Previously, I tried each of the methods suggested here (rebuild, exit Xcode, clean and rebuild, purge Derived Data files). None of them worked.
Once I added the user define build setting per the article, Swift then told me the true error. In my case, it was a missing }, but it could be any number of problems.
I encountered this error when I was upgrading my project from Swift 4 to 5.
I first updated all my pods to their latest versions. When I built, some pods showed this error.
The following steps resolved this issue for me:
Removed all pods from Podfile
Executed pod install to remove all installed pods
Executed pod deintegrate to remove support for CocoaPods
Deleted Podfile.lock and .xcworkspace from my project so no
CocoaPods anymore
Now my project is a pure Xcode project
Opened my project from the regular .xcodeproj file
Changed Swift Version of my project to Swift 5
Cleaned the project (cmd+shift+K)
Quitted Xcode
Restored all pods to my Podfile
Executed pod install to reintegrate CocoaPods and add my pods
Opened the project from the .xcworkspace file
Cleaned and rebuilt
Some old pods that were still using Swift 4.0
(SlideMenuControllerSwift in my case) were set to Swift 5.0, caused
many build errors in their code. I corrected it back to Swift 4.0
by opening the Pods project and selecting its target.
Cleaned again, rebuilt.
Now I have only errors in my own project code related with difference in Swift version I made. My job now is to fix them.
This error happened to me when I forgot to change entity Properties before creating NSManagedObject subclass. Solved by:
delete Entity+CoreDataClass.swift and Entity+CoreDataProperties.swift.
under "class" of the entity model inspector, change "module" to Current Product Module and "codegen" to Manual/None.
recreate the NSManagedObject.
I had the error Command LinkStoryboards failed with a nonzero exit code, and found that I was using a reference to a non-existent storyboard. I had recently changed the name of a storyboard file, so changing the reference from the 'old' name to the 'new' name solved it for me.
You may not have exactly the same error as me, but an easy way to find a more detailed explanation of the error is to:
Show the issue navigator (while the build time error is showing)
Click the error:
Then, you should see more about your error:
I hope this helps. Please, I am aware that I am answering from experience of a different error than this question was asked about, but I believe this advice should help you conquer similar problems!
For me cleaning the project (Command + Shift + K) and restarting xCode worked for me
If you have multiple targets, where two or more targets have files with the same name, check the target membership of those files in Files inspector. The error occurs when multiple instances of the equally named file have set the target membership for the same target.
Since this issue looks to have dozens of possible solutions and the root cause could be very vague, I'll throw my situation into the ring. Half of my pods were failing with some sort of CompileSwiftSource failure, but only on archive. I was still able to build for device and simulator just fine. I tried a lot (if not all) of the solutions suggested here with no luck. One of the pods had a slightly different error before the CompileSwiftSource error so I went to updating and trying to fix that single pod. It was the Cache library for iOS which hadn't been updated in a while. There was a fork that resolved the issue with updating to Xcode 10.2 that I was able to update to and after that, all of the other issues took care of themselves. So look for a single outlier in your pods if you're getting a bunch of them erroring out and start there.
Switching to the legacy build system fixed the issue for me
In my case, I was clean build folder then restart my mac then it's work.
I had the JSONwebtoken pod installed and that was causing issues. I needed to delete the CommonCrypto folder that is in the JSONWebtoken pod folder. Here is a ->link<- explaining the issue. This started happening in Xcode 10.
In my case it was about having a file named Location. after some digging I find out that it was about having two file with the same name (weird). Cause I don't, however, it's been solved by removing the file and adding another file with a different name.
filenames are used to distinguish private declarations with the same name
This can also occur when you have two swift files with the same name. For example, two ContentView.swift files
In my case, I used too complicated initializations inside a class extension. It suddenly broke my build.
class MyClass { }
extension MyClass {
static var var1 = "", var2 = "", var3 = "", var4 = "", ...., var20 = ""
}
Resolved:
class MyClass { }
extension MyClass {
static var var1 = "",
static var var2 = "",
static var var3 = ""
static var var4 = "", ....,
static var var20 = ""
}
In my case it was empty assets catalog, when I delete it everything was fine again.
Command CompileSwift failed with a nonzero exit code
This error happens when you are migrating your code from Xcode 9 to Xcode 10+. It due to any class name is conflicting with existing apple classes. For Example: State, Event etc.
So first change the class/structure name if any existing in your code like "State" to "StateDetail"
If Info.plist is added in target, remove tick mark from it so it will not copy app bundle (Latest Xcode10 security reason).
Select Info.plist file and uncheck under "Target Membership" in right side Identity inspector
And build code again!!!
In my case, the problem was that I assigned a .swift class to the viewController in the storyboard, while the project was Objective C.
I tried a lot of the options discussed here.
Delete and reinstall pods
Clean Build Folder
Delete Derived Data
Add SWIFT_ENABLE_BATCH_MODE and set its value to NO
Restarting Xcode and Recompiling
Restarting iMac and Recompiling
set Compilation Mode to Incremental
Changed build settings: SWIFT_COMPILATION_MODE = singlefile and SWIFT_OPTIMIZATION_LEVEL = "-O"
Nothing worked. I'm using Xcode Version 11.0 beta (11M336w).
Finally I downloaded a fresh copy and replaced the one I had previously installed. It was the same exact version. That did the trick.
I got this error while trying to run my unit tests in a submodule. What I have done is:
Change the simulator => Clean the project => Build the project => Run unit tests.
After this, my unit tests ran without any issue.
I have the issue like that and my solution is change a little thing in Build Settings:
SWIFT_COMPILATION_MODE = singlefile;
SWIFT_OPTIMIZATION_LEVEL = "-O";
it work to me
Alright, I was having the same problem with Xcode 10. I usually use a storyboard for every view, that way if someone is helping it's easier to fold code in. I needed to make one of the view on one storyboard the initial view Controller.
In my case it was renaming a file to an existing file in other folder(Group) by mistake, just rename it to what it was then the error disappeared
The targets should be specified with related data such as appicon
For me the problem was that on my Podfile I didn't put use_frameworks!. I just uncomment that line, run pod install on the terminal again. And it got fixed.
It was commented since the app was entirely made on Objective-C. Since the app now uses Swift I had to make that change on the Podfile
I had the same error Restarting Xcode and Recompiling Fixed the issue for me.
I got the same error when linking separate storyboards. The error, "Command CompileSwiftSources failed with a nonzero exit code." is shown because I simply forgot to set the view controller inside the second storyboard that I am linking as 'an initial view controller'.
In my use case I had used the function "Refactor to Storyboard" in Xcode 13. It created the new refactored story board fine but failed to add it to bundle resources.
So my fix was to:
Select the target project in Xcode Navigator
Choose the build phases tab
Expand Copy Bundled Resources to see if new storyboard was added. If not, just add it to the list and rebuild.
My app was having Notification Service Extension, and was using Xcode 11. The Extension doesn't have anything to do with pods.
After 1-2 years, I have taken that project into my new m1 chip mac with Xcode 13. But the compilation was failing and showing me the error in pods.
I tried to remove and add all pods, tried clean etc all possible available answers available on internet. Almost spent 4-5 hours to make it run, but nothing worked.
Final Solution that worked:
I removed, notification service extension from the project, its target etc too. And then tried to run the app. Amazingly it worked. After that, i added that extension again(by creating new extension and putting the same code again), and everything is working perfectly fine.
I am still surprised that, was that issue with extension or with pods. But finally it worked for me.
Hopefully, this answer might resolve someone's issue and you can save enough time.

Unable to do refactoring on my Swift file in Xcode 9

I am using Xcode 9 and I am trying to do Refactoring on my Swift based file but every time I am getting below error:
Refactoring engine ranges didn't match initial ranges
Why isn't it matching the initial range?
Workaround: Restart Xcode.
This has not been resolved yet as of January 2018 (Xcode 9.2).
Build your project (Command ⌘ + B) and it will fix the error. After doing it, I could rename my file successfully.
I have Xcode's project created using Xcode8 long time ago. For some reason I have to upgrade to Xcode9 (9.4.1 exactly). Then I experienced that error only on that old project, not the new one created using Xcode9.
So i think that error related to project issue. So I decided to compare the settings between old and new one. There are some differences, and after several tries, by changing Optimization Level for Debug solved refactor issue.
In project editor, select your Target, Build Settings
Set Optimization Level (Debug) = No optimization [-Onone]
Delete DerivedData folder related to your project in /Users/YourMacUsername/Library/Developer/Xcode/DerivedData
Clean project shiftcommandk.
Build project commandb.
Update For some reason, it's not happening for me anymore. I noticed also whenever I don't let indexing finishes before trying to start doing a refactor or tap on refactor many times, still see the error, but not permanent anymore.
I asked an engineer at WWDC 2018 about this issue. This issue was happening for me in only one project in my workspace. Other projects in the same workspace works fine. At the moment, there's no solution to this issue. If you want to help Apple to fix this, you can close your Xcode and run following command in terminal:
SOURCEKIT_SERVICE_LOG=3 /Applications/Xcode.app/Contents/MacOS/Xcode 2>&1 | tee /tmp/sk-log.txt
And then try to reproduce the issue and send them the log file (/tmp/sk-log.txt) so they can narrow it down and hopefully fix it in future Xcode versions.
Notice This is project related issue and won't be fixed with OS updates, Xcode updates, or any number of restarting applications, at least the one that I'm having.
I have the same issue in Xcode 10.3.
Refactoring didn't work when I right clicked → refactor → rename on the class name in the class definition. However it did work when I did the same somewhere in code where I use that class.
Product -> Clean Build Folder -> Quit Xcode -> Reopen Project -> Build
I update to Xcode 10 and finally refactoring now it works again after a year without refactoring
I am on Mac M1 and using Xcode Version 12.5 beta 3.
I was facing the same issue when trying to rename ViewController.
Before renaming it, I moved it to a new group, and my code was in a running state. Not sure if that was the reason for the issue.
But I restarted the Xcode and the issue was resolved for me.
I was experiencing the exact same issue. It turned out that I had my build configuration set to Release mode. Changing it to Debug, cleaning build folder and recompiling fixed the issue for me.
Remove DerivedData
This worked for me for this error and other kind of refactoring errors.
Close Xcode
Remove DerivedData:
rm -rf ~/Library/Developer/Xcode/DerivedData
I experienced this on a Mac M1, using Xcode Version 14.1 (14B47b).
This helped:
Clean project: shift-command-k.
Build project: command-b.

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.
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.
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/*
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
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.
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.
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.
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 ~ .
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
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.
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.
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)
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
Too many string concatenations in one line cause troubles. Helped me too.
Originally was pointed by Zhenshan Yu there: Xcode 6 Beta not compiling
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.
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.
Backup your project delete the lastone and restart the xcode simple :-)
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.
I went to tools->task and contexts->clear contexts and that seemed to give the computer rest finally!
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
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.
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.
in my case i had the emulator open with an app builded with previous files. Just close de emulator
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!
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.
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.
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.
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.
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 :)
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

Xcode stuck on Indexing

A project I've been working for 2 months stopped working for no reason because Xcode got stucked on "Indexing". I can't Build the project anymore. If I try to build, Xcode freezes and I have to force quit. This happens only with this project.
I tried cleaning all derived data but didn't help.
I'm using Xcode 4.5.2.
Any ideas?
Open your Project Folder.
Find ProjectName.xcodeproj file.
Right-Click Copy and Paste to Safe Place.
Right-Click Show Package Contents.
Find project.xcworkspace file and delete that file.
Reopen Your Project and clean and Rebuild.
If your problem is not solved then replace the file with your backup file.
Close that project from Xcode
Open Xcode Organizer, find the problematic project
Delete Derived Data folder in the Organizer
Close/re-open Xcode
Nuking Derived Data is the first thing to try in all cases of Xcode misbehaving
I had this exact problem, it was caused by a 20 item array literal. Had to switch to different syntax. Pretty silly.
Close any opened Xcode
rm -rf ~/Library/Developer/Xcode/DerivedData
Right click your PROJECT_NAME.xcworkspace, choose 'show content', and delete 'xcuserdata' folder
Another thing to try if your trying to solve indexing issues and you're this far down the page!
Try adding this flag to your build settings.
-Xfrontend -warn-long-expression-type-checking=400
It will cause warning where the compiler take a long time to deduce a complex expression.
This may cause a build error which will go away after you find the slow expressions and then remove the build flag.
I had a similar problem, and found that I accidentally defined a class as its own subclass. I got no warning or error for this but the compiling got stuck.
class mainClass : mainClass
{
...
}
When using Xcode 6 and it says
Waiting for make
It might be that an instance of make is already running. Kill the process and indexing proceeds. Silly, but worked for me.
This happened to me. If you are using cocoapods do this:
Delete project.xcworkspace
Reinstall pods using pod install on the terminal
It will create a new project.xcworkspace
Open the new project.xcworkspace
-> Clean
-> Build
First, disconnect from network. Both your wired network and wireless network should turn off.
Second, kill the com.apple.dt.SourceKitService process. Then XCode would start to index again instead of stuck.
Hold alt > Product > Clean Build Folder
It's a Xcode bug (Xcode 8.2.1) and I've reported that to Apple, it will happen 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 Apple fixes the bug.
For me completely closing out of Xcode and then restarting the project worked.
This is not the solution for the original question, I don't believe, but it is one more simple thing to try before deleting files and folders, etc. Credit to this answer for the idea.
I had a similar problem where Xcode would spend lots of time indexing and would frequently hang building the project, at which point I had to force-quit and relaunch Xcode. It was very annoying.
Then I noticed a warning in the project about improperly assigning self as a delegate. Sure enough, there was a missing protocol in the class declaration. Note that there is a similar assignment in the OP's sample code (though it is impossible to tell from the sample whether the correct protocol is declared):
leaderboardController.leaderboardDelegate == self;
After resolving that warning (by correctly declaring the implemented protocol), Xcode stopped misbehaving. Also, I should note that the project did execute correctly since the protocol methods were implemented. It was just that Xcode could not confirm that the protocol should in fact implemented by the class.
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.
Nothing worked for me, my project is too big (merging objective c, c++, swift, and java files with j2obj). I've disabled Xcode indexing and worked without code completion for months (and it's a pain). But finally I've found a workaround. The idea is to keep Xcode indexing the code, but to limit its CPU usage 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 mode details : How to prevent Xcode using 100% of CPU when indexing big projects
I'm working with Xcode 11.4.1 and I have the same problem with several projects. Every time, when internet connection is lost, indexing gets up. The best solution (it's just my opinion based on observing this problem):
- turn off internet and just kill the "com.apple...." process, then restart the Xcode(turn on connection)
or more easier
- just restart the Mac(with the internet)
Had similar problem in Xcode 6.4. The progress bar indicated that "Indexing" was "Paused". Tried deleting project.xcworkspace, then deleting Derived Data as described above. Did not appear to help. Noting that the posts above also suggest fixing warnings, and since I had inherited this huge project with 180 warnings, I said to myself, "What the hell this looks like a good day to fix warnings". As I was fixing warnings, a half hour later, I noticed that the "Indexing" progress bar had increased from 10% to about 20%. An hour later, it was at 50%, then another hour to 80%, then after another half hour it was done! Conclusion: Add "take a long lunch or a nap" to the above suggestions.
I experienced the same issue for Xcode 7.0 beta.
In my case, values for "Provisioning Profile" and "Product bundle identifier" of "Build Settings" differed between PROJECT and TARGETS.
I set the same values for them. And I also used the same values for TARGETS of "appName" and "appNameTest".
Then closed the project and reopened it.
That resolved my case.
In my case, deleting the derived data directory did not help. Apparently I had a file locked by another process, because after closing out a couple of terminal windows and emacs, and terminating a react-native packager process, everything resolved.
I have experienced this problem in some projects with Xcode 9.3.1 and in my case the problem is due to some swift code that for some reason Xcode doesn't like. This problem is hard to solve because is difficult to find what file is causing the problem.
When I have this problem, I removing some files from the Xcode project (removing references) and I try to test if indexing works. My process to do so
Remove some files
Close Xcode
Open Xcode
If indexing finish try to rename some method if works probably the files you have removed they have something strange for Xcode.
In my case I had a class definition with a reactive extension in the same file and for some reason Xcode doesn't like it, I moved the reactive extension to another file and now the indexing works fine.
2022 | Algorithm what to do:
Open activity monitor and kill there com.apple.dt.SKAgent
If did not help:
Close Xcode(cmd+Q). Run command in terminal:
rm -rf ~/Library/Developer/Xcode/DerivedData
If did not help:
Restart PC
If did not help:
Right click your PROJECT_NAME.xcworkspace, choose 'show content', and delete 'xcuserdata' folder
If did not help:
run your project build with additional warning. For doing this you need to write:
-Xfrontend -warn-long-expression-type-checking=100
to the following place:
and optimize code at all of places.
If did not help:
Z. Uninstall XCode and install it from scratch
If did not help:
Z+1. answer of El Belga https://stackoverflow.com/a/50541767/4423545
Also stop running app. if you have another application running with your xcode, stop it first and you should have your indexing continue.
For me, the cause was I opened the same file in both the Primary Editor and Assistant Editor at the same time. Once I closed Assistant Editor, it came through. (Xcode Version 7.2.1)
Close Your Xcode , close any git client(source tree or terminal)if it is opened and finally restart your project.
Faced this recently on XCode 7.3.1 - for me, I noticed RAM usage going to 100% on to CleanMyMac3. The problem magically fixed itself after I restarted my machine. In all fairness however, I'd already gone ahead and tried the accepted-answer, so you'll want to do the same before you restart just in case :-)
I fixed this by simply deleting the app from my device and rebuild.
I had the same issue in swift 2.2
It had to do with a generic function overloaded function
func warnLog() {
print("Warning line: \(#line) file: \(#file) ")
}
func warnLog<T>(input:T? = nil) -> T? {
print("Warning line: \(#line) file: \(#file) ")
return input
}
func warnLog<T>(input:T) -> T {
print("Warning line: \(#line) file: \(#file) ")
return input
}
all I needed to do is remove one of the non used overloads
func warnLog<T>(input:T? = nil) -> T? {
print("Warning line: \(#line) file: \(#file) ")
return input
}
My case: it was not the project.xcworkspace file, it was not the Derived Data folder.
I've wasted a lot of time. Worse, no error message. No clue on the part of Xcode. Absolutely lost.
Finally this function (with more than 10 parameters) is responsible.
func animationFrames(level: Float,
image: String,
frame0: String,
frame1: String,
frame2: String,
frame3: String,
frame4: String,
frame5: String,
frame6: String,
frame7: String,
frame8: String,
frame9: String,
frame10: String) {
}
To go crazy! The truth is that it is worrisome (because there is no syntax error, or any type)
For XCode 9.3 indexing issue - Uninstall the XCode and instal again from zero. Works for me.
This issue happened to me when my machine was out of swap space. Closed several programs and browser tabs and the build suddenly succeeded after 30 minutes of being stuck in place. Nothing to do with derived data, locked files, etc. on my side.

Resources