Xcode 8.0 Swift 3.0 slow indexing and building


Solution 1

I solved the problem by commenting all files and then removing comments one by one. I found that the problem is still in the array declaration as described here.

I had code like this and project was not indexing:

class {
    var first: String!
    var second: String!
    var third: String!
    var fourth: String!
    var fifth: String!

    func abc() -> [String] {
        var array = [first, second, third, fourth, fifth]

I've changed it to this and indexing started working:

class {
    var first: String!
    var second: String!
    var third: String!
    var fourth: String!
    var fifth: String!

    func abc() -> [String] {
        var array = [first]


Solution 2

Go to project settings, then Editor > Add Build Setting > Add User-Defined Setting, and add the following:


Adding this flag dropped our clean-build compile times from 7 mins to 65s for a 40KLOC swift project, miraculously. Also can confirm 2 friends have seen similar improvements on enterprise projects.

I can only assume this is some kind of bug in Xcode 8.0

Solution 3

I've had the same issue only since upgrading to Swift 3/XCode 8 and it seems to be caused by large array literals.

I was able to fix the issue by adding type annotations to the variables being assigned to the array literal, e.g.

let array: Array<String> = ["1", "2", "3", "4", "5", "6", "7", "8"]

instead of

let array = ["1", "2", "3", "4", "5", "6", "7", "8"]

Solution 4

I had similar problem and followed this guide to debug : http://irace.me/swift-profiling My problem was i had nil coalescing operator in some strings for example:

let name = "\(someString ?? "")"

and four methods with this were causing 2 min additional building time.

Solution 5

I had the same problem and solved it by painstakingly going through my code line by line, it turns out Swift 3 prefers string interpolation rather than using the + symbol, i.e.

let url = "http://yahoo.com" + "someWebPage" + "whereItsInteresting" 

If you have been using the above style of code replace it for;

let url = "http://yahoo.com\(someWebPage)\(whereItsInteresting)"

And your build time will immediately come back to normal.

Author by


Updated on July 08, 2022


  • Danny
    Danny 6 months

    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 files). I am also using Pods. Indexing of previous Xcode version (< 8.0) worked fast but now, after upgrade, the progress bar is stuck on one position (I am already waiting for an hour).

    Things I've tried that didn't help me:

    • Cleaned the DerivedData folder and restarted Xcode
    • Cleaned the project and restarted Xcode
    • Deleted Pods directory with <project>.xcworkspace and then installed again
    • Restarted Mac
    • Tried build project without Pods
    • Reinstalled Xcode
    • Tried on another Mac with cloned project

    It is really not cool to make such releases of software when developers have to spend hours on solving such ridiculous problems. It is very disappointing. Any ideas how to fix this?

  • Robert Wagstaff
    Robert Wagstaff over 6 years
    Worked for our team too. We are running Xcode 8.0, Swift 2.3 on a codebase that is both Swift and Objective C.
  • Chris
    Chris about 6 years
    @hardik.shah - i have no idea. I couldn't believe it either when it worked.
  • Marco Pappalardo
    Marco Pappalardo about 6 years
    That could be a issue with inferring the type of the array. Instead of using append do that: var array: [String] = [first, second, third, fourth, fifth]
  • n8tr
    n8tr about 6 years
    this took our clean-build time from 6 minutes to 2 minutes! How does this setting differ from the build configuration optimization level and which takes precedence? And how in the world did you discover this? Many thanks
  • Chris
    Chris about 6 years
    @n8tr I'm not sure if this takes precedence over the normal WMO setting. A friend discovered it by accident!
  • Jon Shier
    Jon Shier about 6 years
    No one has mentioned it yet, but this breaks incremental compilation. So while your clean build is now faster, you lose the speed of only having to rebuild a few files at a time when you change one.
  • DonBaron
    DonBaron about 6 years
    the linked guide is the way to go, found the culprit (also nil coalescing operator) in a matter of minutes and was able to amend the code...
  • Zsolt
    Zsolt over 5 years
    This works, but it breaks a number of things that you rely on during development: breakpoints and step through is unreliable, variables are not available when you hit a breakpoint and try to see the content of a variable, command + click to jump to the definition barely works.
  • hstdt
    hstdt over 5 years
    Same reason! the tool https://github.com/RobertGummesson/BuildTimeAnalyzer-for-Xco‌​de helps me find out every bad files.
  • ArgaPK
    ArgaPK about 5 years
    Is the bug fix now?
  • Saeed Ir
    Saeed Ir about 5 years
    Yes, I had reported the bug to Apple and they said they fixed it in the last version of Xcode