**\*Update\*** *This only work for* ***xcodeprojects*** *and* ***not*** *workspaces. Bummer.*
\***Update 2\*** Got workspace configured project to work too. In Complete.swift in SourceKittenDaemon comment out `preprocessorFlags` and `-c` argument. (line 139 and 140).
So 7-8 weeks of struggling with Swift and Emacs and I got it finally to work. A lot of people seems to have alot of problems with Swift and Emacs, lsp package stop working as soon as Apples LSP returns an error, but Eglot handle this much better but there are problems with LSP.
First of all Apple doesnt want you to use LSP for Xcode projects, they officially stated this in their forums. It will not work with XCode projects, only swift packages. But most of us who works professionally uses XCode (.xcodeproj or a workspace).
I tried several options but today I tried `company-sourcekit` and after about of one hour of struggeling to get it work it started working. So here is a short guide:
*This will only work on macOS. Sourcekitten doesnt fully work on Linux yet.*
**Get SourceKittenDaemon**
So here is step by step guide:
1. clone and compile [https://github.com/terhechte/SourceKittenDaemon](https://github.com/terhechte/SourceKittenDaemon). Its a swift package so just double click package.swift and let Xcode do its job one final time. Xcode needs to resolve 5-6 depency packages so it will take sometime before you can build. Have patience.
2. Locate the binary in the build folder: Xcode -> Preferences -> Location -> Derived Data. Open the folder and locate "SourceKittenDaemon" (Build/Products/Debug/sourcekittend)
3. Copy it to `/usr/local/bin`
4. Add it to you PATH (dont know if its needed or not)
**Emacs/your init.el file.**
`(use-package company-sourcekit`
`:config (setq company-sourcekit-verbose nil s`
`ourcekit-verbose nil`
`sourcekit-sourcekittendaemon-executable "/usr/local/bin/sourcekittend")`
`(add-to-list 'company-backends 'company-sourcekit))`
Turn off **Eglot** and **LSP** if you already have configured them.
Launch a terminal/vterm and `cd` to your project.
`$ sourcekittend start --port 8081 --project yourproject.xcodeproj`
Locate the project in Emacs and enjoy auto-completion that hopefully works.
[Full auto-compete on nested types](https://preview.redd.it/1cit0h6l3kg81.png?width=3584&format=png&auto=webp&s=17a34d6a110aa4245b6ade8017ed3147e85da410)