2

I am trying to add an extension to Swift so I can format Doubles as found in this answer here

Precision String Format Specifier In Swift

Not ideal, but best solution I can find so far. However I cannot seem to add extensions to my project. Extensions work fine on playground, but when I try to add it to my project, I get the SourceKit service crash error every time I try to add the code in. I also get an error stating "declaration is only valid at file scope".

I have not previously used extensions in Swift before, so I cannot tell if this is directly related to Xcode 6.1 update or not.

Has anyone else had this issues or know anyway to solve this?

Community
  • 1
  • 1
AdamM
  • 4,400
  • 5
  • 49
  • 95
  • 2
    Are you adding this to an existing file or creating an `Format+Extenstion.swift` file? Just did that in a pretty big project and it seems fine. The `SourceKit service crash` error is pretty annoying and doesn't only happen with Extensions. I have found breaking your project up into different files has helped. – sbarow Oct 31 '14 at 11:14
  • I was under the impression you were allowed to add these extensions into any class, and it would pick up on the extension automatically. – AdamM Oct 31 '14 at 11:29
  • Just tried your way, that seemed to do the trick. If you add that as the answer, I will accept it. – AdamM Oct 31 '14 at 11:35

1 Answers1

2

The SourceKit service crash error is pretty annoying and doesn't only happen with Extensions. I have found breaking your project up into different files has helped.

sbarow
  • 2,759
  • 1
  • 22
  • 37
  • I have a project with several separate files and I still get the SourceKit Service error. I notice that within the text of the report it shows Time Since Wake (I think that's it -- I don't have the message now so I can't check the spelling) is always a multiple of 100. It must be periodically trying to do something. – RobertL Dec 03 '14 at 02:50
  • @RobertL Apple has released Xcode 6.1.1 and one of the fixes is the source code crash. Hopefully that solves it now. – sbarow Dec 03 '14 at 07:19
  • Xcode-Beta 6.3 has still this problem with Extensions. It's really annoying – Carmen Feb 22 '15 at 15:38