I\'ve installed Xcode 8.0 and converted Swift 2.2 to 3.0 (that process also took a lot of time, I just left my Mac running all night). I have not a big project (about 20 fil
I tried the above solutions but the problem still happens. The debugging works weird, too. After some days research I found the solution below.
Select main target > Build Settings. Configuring as image below.
I had a function that took over a minute to compile, and after some investigation, I found that the culprit was checking if enough time had elapsed from a stored date:
let myStoredDate: Double = // Double representing a time in the past
// if at least one week (60 * 60 * 24 * 7 seconds) has passed since myStoredDate
if Date().timeIntervalSince1970 - myStoredDate > (60 * 60 * 24 * 7){
// do stuff
}
This code would take over 10 seconds to compile — coupled with this code being repeated with different numbers multiple times, it was causing compilation to take way too long. I was able to fix this by pre-computing the interval
let myStoredDate = // Double representing a time in the past
//it is important to explicitly specify that the variable is a Double
let interval: Double = 60 * 60 * 24 * 7
if Date().timeIntervalSince1970 - myStoredDate > interval{
// do stuff
}
After doing this with the ~10 times I was checking, the compilation time was cut from over a minute to just a few milliseconds.
It's extremely likely that this problem also occurs with the combination of type-inferance and math elsewhere, so ensure that nothing like this happens anywhere else in your code.
After add the setting,
SWIFT_WHOLE_MODULE_OPTIMIZATION = YES
our project clean-build compile times from 1200s to 180s for 650 swift files. But this will cause increase compile fail. Every change need 180s to compile when increase compile only need 60s
It's a Xcode bug (Xcode 8.2.1) and 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.