Xcode 8.0 Swift 3.0 slow indexing and building

I installed Xcode 8.0 and converted Swift 2.2 to 3.0 (this process also took a lot of time, I just left my Mac all night). I do not have a large project (about 20 files). I also use Pods . Indexing the previous version of Xcode (<8.0) worked quickly, but now, after the upgrade, the progress bar is stuck in one position (I'm already waiting an hour).

Things I tried that didn't help me:

  • DerivedData folder and restart Xcode
  • Tidied the project and restarted Xcode
  • Remote Pods directory with <project>.xcworkspace and then installed again
  • Rebooted Mac
  • Pilot build project without Pods
  • Reinstalled Xcode
  • Tried on another Mac with a cloned project

It's really not great to do such software releases when developers have to spend hours solving such ridiculous problems. This is very disappointing. Any ideas how to fix this?

+52
ios indexing xcode swift3 xcode8
Sep 17 '16 at 13:08
source share
15 answers

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

I had such code, and the project was not indexed:

 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 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] array.append(second) array.append(third) array.append(fourth) array.append(fifth) } } 
+24
Sep 20 '16 at 6:34
source share

Go to the project settings, then select Editor> Add Build Settings> Add Custom Settings and add the following:

 SWIFT_WHOLE_MODULE_OPTIMIZATION = YES 

Adding this flag removed our clean build compilation time from 7 minutes to 65 seconds for a quick 40KLOC project, miraculously. It can also be confirmed that two friends had similar improvements in corporate projects.

I can only assume that this is some bug in Xcode 8.0

+49
09 Oct '16 at 23:17
source share

I had the same problem only from the time I upgraded to Swift 3 / XCode 8, and it seems to be caused by large array literals.

I managed to fix the problem by adding type annotations to variables assigned to an array literal, for example.

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

instead

 let array = ["1", "2", "3", "4", "5", "6", "7", "8"] 
+6
Oct 13 '16 at 22:07
source share

I had a similar problem, and after that the manual was debugged: http://irace.me/swift-profiling My problem was that in some lines I used the nil coalescing operator:

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

and four methods with this caused an additional build time of 2 minutes.

+5
Nov 16 '16 at 8:57
source share

I had the same problem, and I solved it by carefully sorting my code line by line, it turns out that Swift 3 prefers line interpolation instead of using the + character, i.e.

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

If you used the above code style, replace it with:

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

And your build time will immediately return to normal.

+4
Mar 08 '17 at 1:23
source share

for those who want to find where the compiler is "caught"

Add to Other Swift Flags -Xfrontend -warn-long-function-bodies=50

check the full answer here

+3
Jan 22 '17 at 21:26
source share

I tried the above solutions, but the problem is still happening. Debugging works and is weird. After several days of research, I found a solution below.

Select Main Goal> Build Settings. Configuring as image below.

enter image description here

+2
Nov 29 '16 at 4:35
source share

I ran into the same indexing issue, but this only happened when I started / debugged on the device and then switched to another device in the upper left toolbar (Target> iPhone).

None of the above solutions worked for me.

My solution: I deleted my local working copy of git and cloned a new one from my "source".

(Are there some "magic" files in the xcuserdata / shared / session folders, etc. that could cause this problem?)

+1
Mar 25 '17 at 20:19
source share

My problem was in the dictionary. I had a great dictionary.

 let values = ["address":addressTextField.text,"city":cityTextField.text,"zipCode":zipCodeTextField.text,"state":stateTextField.text,"pet":answerLabel.text,"rentStart":rentStartTextField.text,"rentEnd":rentEndTextField.text,"rent":rentTextField.text,"phone":phoneTextField.text,"email":emailTextField.text,"status":leaseStatusTextField.text,"bedrooms":bedroomTextField.text,"parking":parkingLabel.text,"furnish":furnishLabel.text,"utilities":utilitiesTextField.text,"laundry":laundryTextField.text,"paymentCycle":paymentCycleTextField.text,"note":noteTextView.text] 

I broke it into:

  var values = ["address":addressTextField.text] values["city"] = cityTextField.text values["zipCode"] = zipCodeTextField.text values["state"] = stateTextField.text values["pet"] = answerLabel.text values["rentStart"] = rentStartTextField.text values["rentEnd"] = rentEndTextField.text values["rent"] = rentTextField.text values["phone"] = phoneTextField.text values["email"] = emailTextField.text values["status"] = leaseStatusTextField.text values["bedrooms"] = bedroomTextField.text values["parking"] = parkingLabel.text values["furnish"] = furnishLabel.text values["utilities"] = utilitiesTextField.text values["laundry"] = laundryTextField.text values["paymentCycle"] = paymentCycleTextField.text values["note"] = noteTextView.text values["owner"] = userID 
+1
Aug 14 '17 at 13:41 on
source share

After adding the setting

 SWIFT_WHOLE_MODULE_OPTIMIZATION = YES 

The build time of the project from scratch is from 1200 to 180 seconds for 650 fast files. But this will lead to compilation failure. Each change takes 180s to compile, when compilation only increases 60 seconds

0
Dec 14 '16 at 2:39
source share

This is an Xcode bug (Xcode 8.2.1), and this will happen when you have a large dictionary literal or a nested dictionary. You need to break the dictionary into smaller parts and add them using the add method until Apple fixes the error.

0
Feb 07 '17 at 2:19 on
source share

This works for me in Xcode 8.2.1 and Swift 3 when "indexing" is stuck:

I always have two open projects, a dummy project and a project I'm working on. I also have an iPad Air device associated with launching my projects. When my project gets stuck in Indexing, I switch to my layout project and run my project on the connected iPad Air device. Then I stop the project and return to the project I'm working on, and Indexing is magically finished. This should also work only with the simulator if you do not have a physical device connected.

0
Mar 16 '17 at 20:34 on
source share

Not that I thought this was due to an OP problem, but Xcode 8 has recently slowed down for me. In the end, I found that it was my mistake (and I remember how involuntarily) - I added XCode.app as a reference to the Framework. This greatly simplified the search for Xcode and indexing of the entire Xcode.app folder. As soon as I saw the error and deleted the Framework, it became good again :)

0
Jun 14 '17 at 11:20
source share

I had a function that took more than a minute to compile, and after some investigation, I found that the culprit was checking if enough time had passed from the saved 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 will take more than 10 seconds to compile - combined with repeating this code with different numbers several times, which forced the compilation to take too long. I was able to fix this by pre-calculating 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 that, when I checked ~ 10 times, compilation time was reduced from a minute to a few milliseconds.

It is very likely that this problem also occurs with a combination of type-output and mathematics elsewhere, so make sure that nothing like this happens elsewhere in your code.

0
Jul 15 '17 at 20:52
source share

What solves this for me is to use keys to set dictionary values

 let dict: [string:any]() dict["key"] = "value" dict["key1"] = "value" dict["key2"] = "value" return dict 

If you have a long dictionary, it may or may not cause a compilation cycle, which leads to a long build time. Anything longer than 8 keys must be installed.

-one
Apr 13 '17 at 7:46 on
source share



All Articles