sourcekitxcodekit

XcodeKit and SourceKit


I don't have experience in XcodeKit and SourceKit apart from a few articles that I read and the official pages https://developer.apple.com/documentation/xcodekit#topics https://github.com/apple/swift/tree/master/tools/SourceKit

I'm trying to understand the differences between the two and what they are capable of doing exactly.

I think XcodeKit essentially let you add commands to Xcode menu and makes it possible to interact with the source code you have open by creating an app extension which you can then also distribute through the App Store. As far as I could understand XcodeKit only let you get information from the current focused file (not all the files in project), then you can get selected text etc... At least that's what I read until Xcode 9, not sure if things are better now.

SourceKit also interacts with source code but looks like more powerful but more low level.

What I'm wondering is:

https://github.com/apple/swift/blob/master/tools/SourceKit/docs/Protocol.md

Thanks


Solution

  • Depending on your end goal, you have a few options:

    As for your inquiry on retrieving the currently open documents in the editor, your only option would be to use the wonderful scripting interface that Xcode exposes. The Xcode SDEF file can be found at /Applications/Xcode.app/Contents/Resources/Xcode.sdef. You can use the ScriptingBridge framework to do so from a Cocoa application. If you're using Swift, then the SwiftScripting repository is crucially helpful.