242

I am having a issue with Xcode where the error "Source Kit Service Terminated" is popping up and all syntax highlighting and code completion is gone in Swift. How can I fix this?

Here is an example image:

enter image description here

Shruti Thombre
  • 989
  • 4
  • 11
  • 27
Tony
  • 4,609
  • 2
  • 22
  • 32
  • 4
    I just started having this problem... then I spotted a syntax error in my swift file. Once I fixed this the editor started working again. – brindy Jun 06 '14 at 23:45
  • 1
    I get that error when my code causes an infinite loop or a crash (without a proper error being printed) during execution. Continuing to edit the code or removing the bad code restores Xcode's functionality for me. – David Skrundz Jun 08 '14 at 00:35
  • I have also had this issue. I have submitted a bug report to Apple as I was getting this error in multiple situations. Radar #17115239. – Penguin George Jun 03 '14 at 21:19
  • 1
    This appears to be a problem with Xcode beta. Restarting Xcode addressed the problem for me, although on reopening the project the error occurred and then stopped. – ThomasW Jun 03 '14 at 07:04
  • 80
    I would kill for this to be fixed right now... – Andrew Jun 18 '14 at 20:52
  • 2
    The error is indeed caused by a syntax error inside Swift. If you remove the syntax error, the error will go away :) – Steffen Brem Jun 23 '14 at 13:44
  • People, this is quite obviously a bug in Xcode. Please stop posting "me, too" comments and non-answers, because we all have seen this. File a Radar if you want to report this, but please don't clutter up this question. – Brad Larson Oct 14 '14 at 15:26
  • This seems to have been resolved in Xcode 6.1 – Daniel Galasko Oct 25 '14 at 09:31
  • I still get that error on 6.1. Any ideas on how to find out the part of code that's causing the issue? I can't work on my Swift project any more cause it's crashing every 10 sec... – Georg Oct 27 '14 at 13:48
  • 2
    Not only is it not resolved in 6.1, it happens even with the most minor "errors" which aren't even errors. You can often trigger it *while still typing*. I got it to happen when I got as far as the "stru" in "struct". I guess it *really* wanted to tell me something before it got the "ct"! – Maury Markowitz Nov 05 '14 at 15:57
  • It looks like Xcode 6.1.1 has fixes some (maybe not all) of these issues. – Barlow Tucker Nov 19 '14 at 00:09
  • In 6.1.1 I see no improvement. – Rhuantavan Feb 05 '15 at 13:03
  • continues in 7.3.1. I appreciate Santa Claus's sentiments. WWDC around the corner though... – k k Jun 10 '16 at 03:24
  • V frustrating error- for me correcting syntax error, deleting derived data folder and restarting Xcode finally worked. – dancingbush Jul 30 '16 at 13:51
  • I think I figured out why it happens: too complex expressions. See my answer – Lucas van Dongen Dec 05 '16 at 17:02

34 Answers34

114

The answer to mine (Xcode6-Beta7) was simply to delete the Derived Data folder.

Preferences > Locations > Derived Data > click the arrow to open in Finder > trash it.

There's obviously many reasons why this crash can occur.

starball
  • 20,030
  • 7
  • 43
  • 238
tobygriffin
  • 5,339
  • 4
  • 36
  • 61
  • 4
    Seems this fixed the problem, but also using Xcode 6.1 GM. – Flovdis Oct 06 '14 at 11:17
  • Fixed my crash too on 6.0 (release). This should be voted higher. – cud_programmer Oct 08 '14 at 21:54
  • Fixed issue with infinite indexing Xcode Version 6.1 (6A1030) – Dima Deplov Oct 17 '14 at 17:16
  • You are a saint. Losing autocomplete, syntax highlighting, and constant compilation basically removes any advantages to using XCode over a basic text editor. Thank you! – thatidiotguy Oct 31 '14 at 15:01
  • 7
    this fixed it for about 10 minutes, then i changed the name of a variable and it's back! – hariseldon78 Nov 14 '14 at 16:00
  • Would it be unreasonable to get a script to delete Derived Data every time you launch Xcode, or maybe like every 35 seconds? Other than errors, what else does Xcode jam in there? – DanBlakemore Dec 12 '14 at 17:48
  • This didn't always fix the issue but it helped a large percentage of the time which is why it is marked as answer for now until apple updates. – Tony Dec 16 '14 at 16:17
  • 1
    Not a permanent fix but just enhancement of answer.. create a shell script and run it whenever it happens rm -frd ~/Library/Developer/Xcode/DerivedData/* rm -frd ~/Library/Caches/com.apple.dt.Xcode/* – Raj Jan 24 '15 at 09:41
  • 2
    Did not fix my problem – Shirish Kumar Mar 02 '15 at 21:28
35

I believe I may have found a more general purpose solution. Below are the steps I used to encourage Xcode not to produce the SourceKitService Terminated error.


The symptoms I was having:

  • When I would start up a new playground, I would receive an error about not being able to communicate with the playground (Error running playground: Failed prepare for communication with playground. See this image on twitter.
  • When I would switch the playground from OS X to iOS, I would receive another error (unfortunately I did not write that one down).
  • When I would start to type in an iOS based Swift project, attempting to use code completion/intellisense on any UIKit specific class, I would receive the SourceKitService Terminated issue in this thread.

Debugging process:

  • I started by looking through google for SourceKitService, this got very little.
  • I then started monitoring Console.app while using Xcode. This showed a couple errors:
    • IDEPlaygroundDocument: Error encountered running playground
    • com.apple.CoreSimulator.CoreSimulatorService[3952]: The runtime for the selected device is not installed.

What I did to correct this issue.

If you are only having an issue within the context of a Swift project, try this alone first. If that doesn't work, then try all of the steps further below.

  1. Open your project and change the target's deployment target to something <= 7.1.

The more lengthy and involved process. (The first 3 steps are not for sure helpful, but I did them, and so record them here)

  1. Completely delete all copies of Xcode on your system.
  2. Restart your computer.
  3. Reinstall Xcode6-beta only.
  4. Verify that you still have the issue in playground and/or projects.
  5. Open iOS Simulator.
  6. Hardware -> Device -> Manage Devices
  7. Remove all devices.
  8. Recreate all devices you want. I appended the iOS version to the end of the name, just because.
  9. Restart Xcode and the simulator.
  10. Verify that at least playgrounds no longer throw issues when switched from OS X to iOS.
  11. Open your project and change the target's deployment target to something <= 7.1.

Analysis

It appears the issue is with Xcode6 not being able to properly find, and connect, to the simulator. I have not been able to determine why this is the case, but this has allowed me to continue developing with Swift. This may have to do with the fact the simulator binaries seem to have moved.

Community
  • 1
  • 1
Andrew Monshizadeh
  • 1,784
  • 11
  • 16
  • 2
    Had similar problem : "The runtime for the selected device is not installed." error on running playground for iPhonesimulator. Step 5.~9. fixed the issue. – barley Jun 09 '14 at 16:22
  • As a note - Xcode 6 Beta 3 has completely resolved the issue for me. Not sure how or why. Hopefully the same is true for others. – Andrew Monshizadeh Jul 09 '14 at 13:23
  • 2
    Thanks for these steps. I adjusted my deployment target from 7.0 to 7.1 and that seems to have solved the issue for now. – Nick Aug 07 '14 at 01:43
  • Setting the deployment target to 7.1 worked for me, but I'm using framework target along with the app target, so this cause compile failed which is really bad. But I got no code suggestion anymore even the color is back! – Solomon Oct 11 '14 at 17:36
  • 1
    Followed all these steps but it didn't work for me. :-/ – Rohit Goyal Apr 09 '15 at 10:24
  • Do you know what SourceKitService is? – Thellimist Jan 22 '16 at 06:33
32

You just need to delete the "ModuleCache", this is some kind of cache used by Xcode for Autocompletion.

Copy and paste the following line in the Terminal:

rm -rf ~/Library/Developer/Xcode/DerivedData/ModuleCache

David Attias
  • 490
  • 5
  • 15
  • 1
    This did it for me. For a while i could only get highlighting and autocomplete when I had IOS device selected in active scheme. – Wez Nov 12 '14 at 14:36
  • 1
    This worked for me too. According to the release notes [here](http://adcdownload.apple.com//Developer_Tools/xcode_6.1.1_gm_seed_rucg3e/xcode_6.1.1_gm_seed_release_notes.pdf) some of this is fixed in Xcode 6.1.1 GM seed – Jacob Harding Nov 22 '14 at 14:16
  • Alas, years later, and Xcode is most definitely not fixed. Using Xcode 8.1 (8B62) and still getting SourceKitServer crashes every time I click on a symbol. Have cleared derived data, have removed the ModuleCache. Restarted Xcode. Reinstalled Xcode. Installed Xcode on a _new_ machine. Same thing happens. Xcode is a pitiful mess. – Womble Nov 23 '16 at 00:24
27

SourceKitService crashes on my system as soon as I type

extension foo {

I'm using Xcode 6 beta 6 and it does not matter if I type it into an empty file or add it to an existing one. As soon as the source contains one extension block, it will crash. This happens even on newly created projects.

My "solution" is to avoid extension in the sources I'm currently working on. I comment out the end of a class block and the beginning of the extension block. As soon as I have finished my work on the class, I comment them in again:

class MyClass {

    [... my stuff ...]

//}
//
//extension MyClass {

}
Klaas
  • 22,394
  • 11
  • 96
  • 107
  • Just a note - extensions did not do this in beta 5. It's a new beta6 "feature". – Gene De Lisa Aug 21 '14 at 17:19
  • Any other workaround because there are tons of extensions in my project. Can't work with this Xcode now. – Bagusflyer Aug 27 '14 at 01:12
  • This this this so much this. I've discovered that's what is biting me in my most recent projects. Filing a bug report now. – Ben Kreeger Aug 27 '14 at 02:32
  • 2
    Also a huge issue for me. I've taken to just moving extensions to their own file, writing the code in the class, them copy-pasting to the extension. How this snuck through is a little baffling. – Andrew Monshizadeh Aug 27 '14 at 13:23
9

It started happening on my spritekit project after inserting the touchesMoved-function. This function uses forced unwrapping, which seems to cause the problem:

override func touchesMoved(touches: NSSet!, withEvent event: UIEvent!)

After removing the exclamation marks and thus stopping forced unwrapping, the SourceKitService stopped crashing.

Hope this helps!

Markus Buhl
  • 1,484
  • 2
  • 9
  • 5
9

I found a solution on Apple's Developer Forums (which requires login, so I'll explain it here too).

TLDR: Don't import a @protocol in your Objective-C to Swift bridging header that is named the same as an @interface. For example, the Facebook SDK has both a protocol and an interface named "FBGraphObject".

Here's the forum post:

Adding Facebook SDK causes SourceKitService to crash. If you want to use beta 3 and you need Facebook SDK, one work around that I found and is working for me is refactoring Facebook SDK's @protocol FBGraphObject and renaming it to something like @protocol FBGraphObjectProtocol as an @interface FBGraphObject also exists and apparently SourceKit doesn't like it.

It sure is a temporary solution just to keep you functional and you'll have to use Cocoapods or otherwise build Facebook SDK yourself rather than using the framework library.

For the time being, you'll need to make sure you don't have conflicting @protocol and @interface declarations and that includes 3rd party libraries you may be using.

This cost me today, hope it helps!


Posted by e.parto on July 10, 2014

aleclarson
  • 18,087
  • 14
  • 64
  • 91
  • Thanks a lot. It resoled my problem. – Dark Matter Jul 16 '14 at 06:59
  • This bug can surface if you are using Jon Sterling's Pattern for Lightweight Immutability (http://www.jonmsterling.com/posts/2012-12-27-a-pattern-for-immutability.html), since it advises protocols that share a name with their implementation. Renaming the protocols solved the problem for me with no ill effects. – erikprice Jul 19 '14 at 00:46
  • This has been solved for me with Facebook SDK `3.17.1` – KVISH Aug 24 '14 at 00:24
  • This fixed it for me! Thanks – Roman Nov 28 '17 at 08:05
8

Use other name than Swift for the project. "Swift" is reserved.

Marius Fanu
  • 6,589
  • 1
  • 17
  • 19
  • In addition to that it is a bug in editor, when you have error in your code editor is not capable to handle it. It is supposed to give error or warning but it doesn't do all the time. I hope it will get fixed soon. – Gokhan Arik Jun 03 '14 at 20:51
  • 10
    I also receive this warning, but my project's name does not include the word Swift at all, so this is not "the" solution, just maybe "a" solution. And no, I haven't figured out what the issue is with mine. – Andrew Monshizadeh Jun 04 '14 at 14:24
  • 1
    @AndrewMonshizadeh Same problem, no references to Swift but I can barely type a character or two before I get this error. – BytesGuy Jun 04 '14 at 17:22
  • 1
    Further investigation has led me to determine that I receive the SourceKitService Terminated error when I attempt to use code completion on a subclass of `UIView`. – Andrew Monshizadeh Jun 07 '14 at 14:51
  • 4
    This is not the cause of the issue. I have no idea why this is upvoted. – Andrew Jun 18 '14 at 18:40
  • Nowhere did OP say what he called his project, so this answer is completely irrelevant. – NRitH Jul 02 '14 at 01:49
  • 1
    NRitH, I had this problem when using Xcode 6 beta 1 and changing the project was a fix that worked for me. There are probably numerous bugs that trigger this error. You're probably using a newer version of Xcode and they probably fixed that bug. – Marius Fanu Jul 02 '14 at 11:09
8

I had this problem every few seconds in Xcode 6 Beta 3, and it continued even in completely new projects. I changed the Deployment Target from 8.0 to 7.1 and it has stopped.

Caroline
  • 4,875
  • 2
  • 31
  • 47
5

Is your project named Swift? With seeing that message, build would be failed too(<unknown>:0: error: module name "Swift" is reserved for the standard library). Try using another project name such as SwiftTest. It would work.

devxoul
  • 2,128
  • 1
  • 16
  • 13
3

In order to fix this you may have some weird issue with your Swift code. For instance having multiple defintions of IBOutlets because you were in the middle of copying and pasting. usually it is just a syntax error that couldnt be handled.

Tony
  • 4,609
  • 2
  • 22
  • 32
  • 2
    I'm seeing this problem with unmodified code from an Xcode project template, so I don't think it is an issue with the Swift code. – ThomasW Jun 03 '14 at 07:03
  • It can be caused by multiple IBOutlets with the same name. – Tony Jun 03 '14 at 19:50
3

I found that by explicitly (statically) typing the variable types, rather than inferring them, solved the issue for me.

Olshansky
  • 5,904
  • 8
  • 32
  • 47
3

Quit Xcode if it's open. Then from Terminal run:

defaults delete com.apple.dt.Xcode

This will restore Xcode to the default settings. Open Xcode and everything should work again.

nobody
  • 19,814
  • 17
  • 56
  • 77
Ross Gibson
  • 980
  • 1
  • 8
  • 14
2

For me (xcode 6.1) reason was that I forgot to adopt my subclass to protocol.

For example this is wrong:

protocol SomeProtocol { ... }
class A :NSObject, SomeProtocol {
...
}
class B : A {
...
}

and this is ok:

protocol SomeProtocol { ... }
class A : NSObject, SomeProtocol {
...
}
class B : A, SomeProtocol {
...
}
Ivo Leko
  • 720
  • 1
  • 10
  • 20
  • Had the same issue with forgotten protocol. Thank you for your advice. Seems release version of xcode still works like beta =) – John Kakon Oct 28 '14 at 09:50
  • Thanks! I've been going crazy over this. Your solution fixed my issue. I hope this will be fixed, seems strange to have to add protocols on every subclass.. – Alvin Nov 19 '14 at 20:58
1

A program consisting only of these two lines (possibly wrong in terms of Swift syntax) is enough to cause the "SourceKitService Terminated" error here:

var x = 42
println("Hello", x)

Using let instead of var makes the editor behave normally again. Xcode version 6.0 (6A215l)

Alexander
  • 9,737
  • 4
  • 53
  • 59
  • I generally suspect this bug comes up when Xcode can't handle a certain syntax error -- in the actual code or while making the build (in the example of having swift in the project name) – Lyndsey Scott Jul 16 '14 at 12:22
  • I'm saying the bug is probably caused by a syntax error and since your code has a clear syntax error, it's in line with my theory. – Lyndsey Scott Jul 18 '14 at 00:13
  • "SourceKitService Terminated" as a response to a syntax error makes no sense. This is the error I was pointing out. This is the bug in question. – Alexander Jul 19 '14 at 14:06
  • Yes. That's the meaning of the word "bug". This **bug** seems to be triggered by syntax errors. Hopefully Apple will fix it soon. – Lyndsey Scott Jul 19 '14 at 16:05
1

Got same issue today, the thing was with println, I just tried the old NSLog style to print a value:

// something like this
println("value = %@", valueObj)

The way how we should compose strings in swift has evolved from printf style to inline style, so now you embed your values right into the format string like this:

"Here goes \(YOUR_VARIABLE)"

So, for the example above the solution is:

println("value =\(valueObj)")
MANIAK_dobrii
  • 6,014
  • 3
  • 28
  • 55
  • Hey, @downwoter, what's wrong with this answer? Seems good to me. I know we still could use NSLog with Swift, but println is the way to do since Swift. And this answer directly relates to the problem, the described line crashes SourceKit service. – MANIAK_dobrii Jun 23 '14 at 07:10
  • I had a similar issue with a println() was trying to print an unnamed tuple – thisispete Jul 05 '14 at 20:24
1

I had same issue with Xcode6 beta 3 for a project created in beta 2.

It was because of new breaking changes in swift language i.e. array declaration syntax.

Check for the effected code due to breaking changes in beta 3.

http://adcdownload.apple.com//Developer_Tools/xcode_6_beta_3_lpw27r/xcode_6_beta_3_release_notes__.pdf

One of the example in my case was:

I had to change:

var tabBarController : UITabBarController = self.window?.rootViewController as UITabBarController;

to

var tabBarController : UITabBarController = self.window!.rootViewController as UITabBarController

Conclusion: Looks like if there is an error in source code, in some conditions this error is produced by Xcode.

Solution till the bug is fixed: Check for the error manually :)

Goodluck!

Tejasvi Hegde
  • 2,694
  • 28
  • 20
1

The solution for me happened to be changing the simulator. I was using iPhone 5S for my simulator and when I switched it to iPhone 5, everything worked perfectly. Hopefully a future version will fix it altogether.

Fomentia
  • 904
  • 7
  • 12
1

I found that removing derived data from terminal resolves the issue until next crash. :S

It is located at: /Users/{User name}/Library/Developer/Xcode/DerivedData/{Project Name}-{Random char sequence}

I hope this helps.

sang
  • 337
  • 3
  • 9
1

I think I figured out one (as there are probably many) of the reasons this occurs.

In my case, I was importing Objective-C files through the Bridging Header that had one of the following true:

  1. The implementation file (.m) for the Objective-C import, did not have the app target properly set.
  2. The Objective-C file only had a header (.h) file and NOT an implementation (.m) file. (Again, I think this is part of the "no proper app target" set, as you can only set targets in the .m files and not the .h files)

Fixing the app targets on the Objective-C files OR removing the import of those file(s) in the Bridging Header all together seems to fix the issue.

FYI - If you need to set the target of Header (.h) files that have no Implementation (.m) file, you can follow these simple steps: Can't change target membership visibility in Xcode 4.5

Community
  • 1
  • 1
JimmyJammed
  • 9,598
  • 19
  • 79
  • 146
1

Just to add one more potential solution here, I had accidentally named a class var the same name as it's type:

class var Settings:Settings {
        get { return classVarWorkAround.settings }
    }

This will crash SourceKit FOR SURE. Stupid syntax error, but in case anyone else makes the same mistake.

Edit: also according to @Portland Runner:

Similarly, If you set the return type to the func name you'll get the error.

func foo() ->foo{}
ohhh
  • 972
  • 9
  • 24
  • 1
    Similarly, If you set the return type to the func name you'll get the error. `func foo() ->foo{}` _(feel free to add it into your answer)_ – Automate This Apr 01 '15 at 22:03
0

When this error starts popping up, just comment out the last/recent piece of code you wrote and wait for a while. The syntax highlighting should reappear. This is how I work around the problem.

    func someFunc() -> (Int?, Int?, Int?) {
     var retVal1:Int? = nil
     var retVal2:Int? = nil
     var retVal3:Int? = nil

     //some other code

     //commenting out the line below helped me
     //(retVal1, retVal2, retVal3)
     return (retVal1, retVal2, retVal3)
    }
Hong Wei
  • 1,397
  • 1
  • 11
  • 16
  • The system re-boots itself regardless of anything you do. You do not have to comment out the line, it will still start running again shortly. And crashing too, of course. – Maury Markowitz Nov 05 '14 at 15:58
0

Reported to Apple (#17266321) :

Details:

Summary: If we try to print a dictionary with value as an array a pop-up keeps on popping saying -"SourceKit terminated. Editor functionality temporaly limited". Xcode Freezes and looses context recognition causing text to be blackened.

Steps to Reproduce: 1. Create an array as - "var iOSHistoryArray = ["iOS6","iOS7","iOS8",]"

  1. Create an dictionary as -"var MacOSYosemiteFeatures:Dictionary = ["Device":iOSHistoryArray]".

  2. Print the dictionary as - "println("Dictionary containing Array value : %@ \n",MacOSYosemiteFeatures)" (<<- Culprit-->>)

  3. The step 3 causes the issue commenting which makes the Xcode functional again.

Expected Results: Xcode should function normally.

Actual Results: Xcode becomes nonfunctional, looses context recognition (All font is lost and all text becomes plain black), whole Xcode becomes Inactive.

Version: Version 6.0 (6A215l)

aksani56
  • 606
  • 2
  • 6
  • 14
0

Try It:

There is a bug in the Swift compiler / indexer. Some line or lines in your code is giving it difficulty. You will have to edit your code with some other text editor to comment out the offending line(s) before you will be able to open that project with Xcode. If you have no clue what the problem is, comment out all your code. Once you have the project open, you can start bringing back code little by little until the rise in CPU activity tells you that you've found the problem.

  • @Pang if answers are correctly valid and the same then the questions are probably duplicates so you should vote or flag to close them - In this case this is definitely the open to keep – mmmmmm Aug 08 '14 at 20:21
0

Problem:

  • If there is an error in source code, the "SourceKitService Terminated" pop up may appear and code highlighting stops working. It may or may not happen, when it does its under multiple different conditions.

My case: Installed beta 3, OSX only project, one file detected the "half-closed range operator has been changed from .. to ..<" error. The pop up starts appearing and code highlighting starts failing.

Solution:

  • Fix error detected by Xcode
  • Change to a different .swift in Navigator, come back to the original
  • Syntax highlighting reappears and "SourceKitService Terminated" pop up is gone
Luis Palacios
  • 396
  • 1
  • 3
  • 14
0

In xcode, go to your menu bar >> window >> devices (shift+cmd+2) a new window will pop up, and on the bottom left, add a new simulator, specifically one running on iOS 8.0 to the existing list edit: you might need to restart xcode

refrence:http://www.reddit.com/r/swift/comments/2bznfo/error_running_playground_unable_to_find_suitable/

frank
  • 2,327
  • 1
  • 18
  • 20
0

In my case I had imported missing files in bridged header. After I deleted wrong imports the error notification gone.

Shmidt
  • 16,436
  • 18
  • 88
  • 136
0

I had the same error with the nested Objective-C++ project that now includes Framework with Swift code. In order to fix this issue I had to explicitly build the framework. Once I did that issue is gone, and doesn't come back ;)

Anton Matosov
  • 1,685
  • 1
  • 20
  • 19
0

Still happening with xcode 6 Version 6.0 (6A313)

  • Create a new project
  • Add a Framework & Library
  • Select cocoa touch framework
  • Add a Swift file
  • Add a class to the swift file

Crashes

ps: brand new mac mini, no previous xcode installs, nothing exotic. Just a beta product I suppose.

Alex Nolasco
  • 18,750
  • 9
  • 86
  • 81
0

Xcode 6.1 Beta 3:

As soon as you define a non-private type alias (e.g. typealias Foo = Int) in one Swift file an type the letter c in another file the SourceKitService crashes.

Solution is either resign from using type aliases, wait for the next beta release or wrap your type aliases in class definitions:

public class DummyClass {
    public typealias Foo = String
}

and use it like this:

var myVar:DummyClass.Foo?
Klaas
  • 22,394
  • 11
  • 96
  • 107
0

Changing the deployment target to iOS 8.0 worked for me. I know someone said moving it to <=7.1 worked, but this problem seems to come in from multiple sources, so this alternative may work.

Maxwell
  • 6,532
  • 4
  • 37
  • 55
0

So far the 2 most common causes for me have been:

  • semicolons at the end of lines
  • importing frameworks that are not referenced in the file
thisispete
  • 176
  • 1
  • 9
0

Move the extension before the principal class.

extension SomeType {
// new functionality to add 

}

gerachev
  • 121
  • 1
  • 4
0

I've had this coming up almost every day for the past few months. Tried all the above and it only fixes it temporarily.

Finally, two weeks ago I changed the location of the DerivedData location to a fresh location and I haven't had the issue once.

I note that when I delete my Derived Data folder it regenerates and is about 3GB for some reason. When I created a new folder it didn't regenerate all this data.

Hope this helps someone.

bwash70
  • 1,135
  • 2
  • 11
  • 24
0

Swift tries to figure out what type everything is dynamically rather than statically, but that can take an enormous effort when it's dealing with complex types (like chained filter, map, flatMap calls) or large dictionaries. Sometimes you need to break them up to make it easier for the compiler to analyze. A cousin of this problem is the error "too complex to evaluate in time". Imagine having a few of those that were almost too complex to evaluate in time: together they become a resource hog.

Try to find all places where you create dynamic dictionaries or use chains of untyped calls. Try to type more specifically, especially at the declaration of the variable.

Some quick examples:

Dictionaries

Bad:

let myDict = [ /* bunch of different things */ ]

Better:

let myDict: [String: AnyObject] = [ /* bunch of different things */ ] 

Best:

let myDict: [String: SpecificType] = [ /* bunch of similar things */ ]

Mappings

Bad:

let filteredUserIds = users.filter({ user in user.enabled })
    .flatMap { user in user.name != nil ? return user.id : return nil }

Better:

let filteredUserIds: [Int] = users.filter({ user in user.enabled })
    .flatMap { user in user.name != nil ? return user.id : return nil }

Best:

let enabledUsers: [User] = users.filter { user in user.enabled } 
let filteredUserIds: [Int] = enabledUsers.flatMap { 
    user in user.name != nil ? return user.id : return nil 
}

The benefits also are extra checked code as you will always either get the expected type or a compiler error. The downside is that it starts to look a bit like Java.

Of course this problem accumulates first while your project grows. Small Swift projects are always fast. So probably it's a lot of work. Experience tells what expressions are complicated and time intensive. It would be great if you could benchmark these kind of things.

Lucas van Dongen
  • 9,328
  • 7
  • 39
  • 60