Reputation: 63054
I'm running Xcode 7.3.1. When building my Swift based project, it hangs on "Compiling Swift source files". I've tried various combination of deleting DerivedData
, clean, run, restarting Xcode, restarting OS X, none seem to work. Any ideas?
Upvotes: 23
Views: 23387
Reputation: 2421
Just check if any duplicated files added or missing files in Compile Sources
in Build Phases
.
In my case
These will happen if you rebase
or cherry-pick
.
Upvotes: 0
Reputation: 4546
Something I found useful was the post from RoystonP on https://developer.apple.com/forums/thread/115303?answerId=391817022#391817022:
- Open Activity Monitor.
- Start your project building.
- Wait for the the build’s progress to completely stop for several minutes.
- Locate the Swift processes in Activity Monitor (they should be using nearly 100% CPU) and select one of them.
- In the menu bar, select “View”, then “Send Signal To Process…”
- Select “Abort (SIGABRT)” from the drop-down list.
- Click the “Send” button. This will simulate an assertion failing, so the compiler will print information about what it’s doing and then exit.
- In Xcode, switch to the Report Navigator (the “speech bubble” button over the left-side pane) and select the build.
- Scroll down to the now-failed compilation step and click the transcript button (button with five lines, to the right of the “Compile [Filename]” line).
- Scroll down to see the diagnostic information. It will probably include a list of command-line flags, a few lines saying things like “In pass SimplifyCFG”, and a stack trace.
You might have to repeat step 6 and 7 in order to get it to work.
Upvotes: 15
Reputation: 1152
What I came across the bug is that The compiler is unable to type-check this expression in reasonable time; try breaking up the expression into distinct sub-expressions
I missed a left arrow here.
Upvotes: 0
Reputation: 6373
So I believe that in most cases it's well known dictionary literal type interference problem.
Code like this:
let params = [
"title": title, "desc": desc, "velikost": velikost,
"cena": cena, "vykon": vykon, "telefon": telefon,
"rokVyroby": rokVyroby, "stkDo": stkDo,
"zemePuvodu": zemePuvodu, "najetoKilometru": najetoKilometru,
"stav": stav, "ZnackaId": znackaId,
"VyrobceId": vyrobceId,
"category": categoryId, "subCategory": subCategoryId,
"modely[]": modelId, "prodejNakup": prodejNakup,
"mena": mena, "isNovy": isNovy, "serviska": serviska,
"abs": abs, "technicak": technicak,
]
Have to be written better always like this:
let params: [String: String] = [
"title": title, "desc": desc, "velikost": velikost,
"cena": cena, "vykon": vykon, "telefon": telefon,
"rokVyroby": rokVyroby, "stkDo": stkDo,
"zemePuvodu": zemePuvodu, "najetoKilometru": najetoKilometru,
"stav": stav, "ZnackaId": znackaId,
"VyrobceId": vyrobceId,
"category": categoryId, "subCategory": subCategoryId,
"modely[]": modelId, "prodejNakup": prodejNakup,
"mena": mena, "isNovy": isNovy, "serviska": serviska,
"abs": abs, "technicak": technicak,
]
But I believe that even shorter literals are issue and to save time by waiting for build it's better to always define type for dictionary literals so compiler don't have to find out by himself, as he obviously struggle. PS: I think apple engineers have some serious personal problems there, they have to hire some people from Jatbrains or maybe even me ;) to focus on important things and not waste time on discussions on how Swift have to be different from others...
Upvotes: 0
Reputation: 989
There seems to be various possible causes of extremely long compilation time. Corner or edge cases are everywhere. So the best way is to observe and investigate your own case.
Although being mentioned by others in comments, but steps below still worths more attention:
Build
task. See which source file is taking up a lot of compiling time.Upvotes: 5
Reputation: 41
I had the same problem. In my case it seems to be a result of applying too many nil coalescing actions. I was building a json item:
json = [ "item1": value1 ?? "",
"item2": value2 ?? "",
"item3": value3 ?? "",
...
"item14": value14 ?? "" ]
This wouldn't compile. When I removed all the nil coalescing so that it looked like the following, it compiled fine.
json = [ "item1": value 1,
"item2": value 2,
"item3": value 3,
...
"item14": value 14 ]
I did not try to figure out the cutoff point for the number of items before it got stuck.
Upvotes: 4
Reputation: 331
In my case XCode stucks on big dictionary literal:
requestParameters = [
"asset" : "...",
"user" : "...",
// about 15 additional keys
]
The problem was fixed after replacing this part by:
var requestParameters = [String : Any]()
requestParameters["asset"] = "..."
requestParameters["user"] = "..."
// about 15 additional keys
Upvotes: 0
Reputation: 690
I made a class extend itself. That also causes Swift compiler to get stuck in a loop without error:
class X: X
Upvotes: 25
Reputation: 382
xcode seems to have a problem concatenating more than 5 strings. See this: Xcode freezes when trying to execute this in a Swift playground? The given workaround solved my problem
Upvotes: 0
Reputation: 1915
Change "Swift Compiler Optimization Level" in Build Settings from "Whole module optimization" to "Single file optimization". It may not be your problem, but it solved mine I was stuck with for half a day. It may just be a temporary bug in the recent Xcode version (8.2.1 was the one I have been using at the time I wrote this).
Upvotes: 7
Reputation: 364
In my case the problem was during JSON parsing. I was sending an optional value in a dictionary parameter during JSON parsing.
Upvotes: 2
Reputation: 6882
Try clean your Project Build Folder
Pod Install
or Pod Update
I think 2 is probably the cause.
Upvotes: 7
Reputation: 63054
Thanks for all commentors' suggestions. I narrowed it down to a map
's closure referencing a property that I had removed. Example:
var people: [Person] = ...
let foo = people.map { "\($0.name), \($0.age)" }
where Person
looks something like:
protocol Person {
var name: String { get }
var age: Int { get }
}
This all works fine. Then I removed age
while keeping the closure unchanged. This caused Xcode to become hopelessly confused. Probably related to the Swift's type inference.
Upvotes: 8