0

I started having peculiar problems when using XCode. Whenever I try to write test with swift, XCode shows an internal error and all the code turns white.

This happens even if I remove the @testable annotation from the code.

I tried reinstalling XCode, but this did not help. The code builds just fine so I don't have a clue where the problem might lie.

I'm unable to properly develop tests this way, my modules are not recognised, I have no error checking or code completion.

Here is a screenshot of how the problem looks: XCode bug

Would love to get any guidance on this issue...

nhgrif
  • 61,578
  • 25
  • 134
  • 173
maxandron
  • 1,650
  • 2
  • 12
  • 16
  • Yeah that's SourceKit crashing ... I don't think you can do much there (except you have experience with this kind of stuff, it's open source). – HAS Apr 23 '16 at 12:32
  • I find that sometimes [cleaning the derived data folder](http://stackoverflow.com/a/33736123/2227743) helps with this kind of crash. Also sometimes Xcode can freak out like this if the targets for each related files are not consistent. – Eric Aya Apr 23 '16 at 12:43
  • Didn't help Eric, thank you. I wonder what is different in my setup as opposed to other people, people do test code in ios, why can't I? – maxandron Apr 23 '16 at 13:58
  • 1
    It's sometimes good to create a new user account and see whether an application runs better completely clean. If it does, you can be fairly sure it's something connected to saved data rather than your system or the application itself. – Phillip Mills Apr 23 '16 at 14:07
  • Thanks, I'll try that – maxandron Apr 23 '16 at 14:08
  • I'm not having this exact issue, but what I found in general with SourceKit crashes is that restarting Xcode helps a lot (sometimes it's enough to just switch to another file and back, but the latest dev snapshot [2016-04-12] is giving me a really hard time ... @maxandron Are you using the version of Swift that comes with Xcode or did you install additional toolchains? – HAS Apr 23 '16 at 18:27

1 Answers1

1

So I guess for now there is no good solution to this problem. It seems to be caused by crashes of SourceKit.

Fortunately the problem is not solved (partially) on my end.

I decided to make this answer a compilation of different things to try when experiencing this:

  • Restart - try restarting both Xcode and the PC
  • Clean the project (shift-command-K)
  • Build your code, I noticed that sometimes it occurs when you just have unrelated build errors somewhere in your project - make sure it builds
  • Delete the DerivedData folder rm -Rf ~/Library/Developer/Xcode/DerivedData/, but you can also delete it from Xcode
  • Delete the cache rm -Rf ~/Library/Caches/com.apple.dt.Xcode - Currently this seems to help the most

I will edit and add more solutions if I find any

Community
  • 1
  • 1
maxandron
  • 1,650
  • 2
  • 12
  • 16