xcode 7.1: Compiling Swift source files never completes

I'm upgrading a project written in Swift 1.2 with part of the code on Objective-C to iOS 9 (Swift 2). I haven't been able to build it in xcode 7 nor 7.1; it starts, but it never completes. I wasn't able to use the xcode tool to convert my project to the latest Swift syntax because it doesn't finish (I've left it there around half an hour).


At the beginning, it presented errors and warnings, and I solved them one by one. Currently, there are no more (visible) errors, but it doens't finish compiling ever.


In the Report navigator, the current build (it's been running for more than 40 minutes now) shows the animated loader icon, and when I click on it, and show "All messages", it looks like this:


[ Checked ] Create product structure

[ Checked ] Run custom shell script 'Check Pods Manifest.lock'

[ Gray ] Compile Swift source files

[ Green ] Compile HomeImageView.swift ...
[ Green ] .......

[ Green ] < several .swift files ... >

[ Green ] .......

[ Gray ] TransactionsViewController.swift

[ Gray ] ... < 3 more .swift files >


Also, if I run "top" from the terminal, these are the lines corresponding to xcode processes:


PID COMMAND %CPU TIME #TH #WQ #PORT MEM PURG CMPRS PGRP PPID STATE BOOSTS

5177 swift 97.4 46:38.18 1/1 0 9 55M 0B 20M 5148 5148 running *0[1]

5148 swift 0.0 00:00.16 1 0 9 428K 0B 3140K 5148 606 sleeping *0[1]

606 Xcode 3.8 10:33.81 24 9 436 551M 33M 95M 606 1 stuck *0[2176]


So, the machine is working a lot... But I can't figure out why is it taking so long, and the 4 files it hasn't compiled are the same ones since I started building the project.


I've tried cleaning the project, closing xcode, restarting my Mac...

Replies

Hello Apple? My project won't compile as well... "Compiling Swift source files" forever... Can we get some help please?

I have the same problem as well. I just bought a new Macbook Pro and want to test my iOS app using it. But it doesn't compile. Even the "indexing" takes forever, and if I try to build or run, it will stuck on "compiling swift source files".

Check for SWIFT_WHOLE_MODULE_OPTIMIZATION = YES in your build settings, remove it if is present.

There was no entry for "SWIFT_WHOLE_MODULE_OPTIMIZATION = YES" in build settings. At least not in my iOS project

Xcode stuck indexing error (compiling model, copying swiftdocs, etc.)

  1. Open your Project Folder.
  2. Find ProjectName.xcodeproj file.
  3. Right-Click Copy and Paste to Safe Place.
  4. Right-Click Show Package Contents.
  5. Find project.xcworkspace file and delete that file.
  6. Reopen Your Project and clean and Rebuild.

If your problem is not solved then replace the file with your backup file.


(Works in some cases, still investigating the cause)


Generally, you can switch to the Report Navigator (Cmd-8) during the build and follow along while Xcode processes each file. This will at least allow you to isolate the problem.


Update:

In one instance, I found that the recurring problem was resolved after updating the OS X to the latest beta. At this point I no longer see the error when running Xcode 7.1.1 and OS X 10.11.2 Beta (15C40a).

I was getting the same issue. I did all the above suggestions and nothing worked. Untill...


I restarted my Mac...works now. I thought I got rid of my PC...oh well.

Hello Guys,

Might be a bit late but this fixed the issue on my side (nothing from the above worked). And it took me 2 days to figure out what the **** was going on.

In summary:

I had a pretty common in length inline json like object:

let response: [
  GameBonusType.FreeSpin : [
       [
            ["DD", "AA", "KK", "HH"],
            ["CC", "JJ", "KK", "CC"],
            ["HH", "FF", "KK", "II"],
            ["WW", "CC", "JJ", "DD"],
            ["EE", "CC", "HH", "EE"]
       ],
       [
            "bonus": "JJ",
            "position": [1, 2, 3, 4, 5]
       ]
     ]
]
// GameBonusType is Objc Enum of type NSUInteger


This completely freaked out the swift compiler and the project never completed to build (also indexing never completed). The way I managed to fix it was to predefine some of the inner Arrays/Dictionaries outside of the above "big" definition.

I started to have this issue as well. When arching the target, xcode hangs in "copying swiftdocs". I restarted the computer and it solve the issue in that moment, after a while i had to archive again and the issue came back. Restarted again and it worked. But i am afraid is a visious circle.

Something is not well in xCode 7.2.

I created a bug report, lets see what support says

I have run into the same issue in 7.3 Beta, and after doing every recommended step short of re-installing Xcode and continuing to get the failure, I diffed the changes in my source since the last commit (after which the it started misbehaving), and selectively commented the changes out.


I had declared an enum error class as _ObjectiveCBridgeableErrorType, and had also added new arguments to 4 methods declared in a protocol widely adopted in a project submodule. Commenting out the _ObjectiveCBridgeableErrorType and the few places I was throwing it, and suddenly I got a bunch of errors (how pleasantly surprised I was to get build errors!) with those implemented protocol methods I had not yet changed.


I have changed the remainder of the methods and I'm getting a clean build -- I suspect there was a massive circular dependency somewhere -- In Activity Monitor I saw it had spawned 7 or 8 swift processes each eating up as much CPU as possible. Sigh.

This approach helped me. Thanks for the pointer @joeybladb.


After commenting out a few lines, it was clear that the following, which appeared a handful of times, was causing indexing to fail:


print(String(#line) + " " + String(#function) + ": Some message")

This helped me. Swift source code compile time kept on increasing, but I couldn't figure out why. It turns out that it was my literal dictionary array declaration for userDefaults, with (23) items. Once I switched it to a var, adding each of the 23 items seperately, all compiled well. I found it by looking at the Report Navigator. Before breaking the literal dictionary down, the class it was in would not compile, at least not in a reasonable amount of time.


I'm running Xcode 7.3, Swift 2.2.

I had the same issue with xcode 7 compiling forever. What I found is the initialization of map() in array caused the issue. I switched to use append() manually and the problem is solved. Here is the detail study http://applytech.me/blog/build-stuck-after-upgrading-from-xcode-6-to-xcode-7/ Hope it helps

Same fix here. Thanks a bunch! Way faster now.

I found this worked for me:

  1. Open Keychain
  2. Search for AppleID certificates (I found 1300+ of them)
  3. Delete all of them

http://stackoverflow.com/questions/39934254/xcode-8-preparing-archive-takes-forever

I had the same error message when I upgraded my XCode project to the swift 3.0 version.

I resolved it after defining all my arrays:


from here:

let lobosJuego = [[lobo1BrazoDcho, lobo1AntebrazoDcho, lobo1BrazoIzq, lobo1AntebrazoIzq], .... ]

to here:

let lobosJuego: [[SKNode]] = [[lobo1BrazoDcho, lobo1AntebrazoDcho, lobo1BrazoIzq, lobo1AntebrazoIzq], ... ]


then I have been hable to compile.