Skip to main content
On this page

Set up Swift code completion in VS Code for Xcode projects

Completion, go to definition and live errors for Swift, SwiftUI and Objective-C, third-party libraries, and what to do when completion is off.

Last updated

Swift code completion in VS Code works as soon as you open your iOS project. KXApp gives Swift, SwiftUI, Objective-C, C and C++ code completion, go to definition, hover docs, find references and live errors. Results follow your project's real settings, just as accurate as writing code in Xcode. The first open takes a few seconds to get ready, and Swift Package and CocoaPods libraries get completion after one build, which the extension runs for you in the background.

What happens the first time I open a project?

The first time you open a project, the extension adds a buildServer.json to the project root. Code completion needs it, and you can add it to .gitignore. If you've used a tool such as xcode-build-server and the file already exists, it's left alone; to switch to KXApp's completion, delete it and reload the window.

SPM dependencies, CocoaPods and the app's own modules need a build before they can be completed. If the project hasn't been built yet, the extension quietly builds the current scheme in the background (without signing), so completion usually appears within seconds. A build you start yourself takes over right away. To turn the background build off, disable kxapp.build.prepareForCodeCompletion.

Does code completion follow the scheme I switch to?

Yes. Results follow the selected scheme, configuration and run device, and update when you switch. "No such module" errors from before the first build clear up by themselves once the build finishes.

What do I do when Swift code completion looks wrong?

CommandWhen to use it
kxapp: Restart Code CompletionCompletion is stuck or diagnostics are clearly out of date
kxapp: Re-Index ProjectGo to Definition or Find References misses symbols that exist

VS Code treats .h files as C++ by default. Completion still works, but Objective-C highlighting is off. Add this to your settings:

"files.associations": { "*.h": "objective-c" }

Which settings affect code completion?

SettingDescription
kxapp.swiftSourcekitLspSupportedLanguagesLanguages handled by SourceKit-LSP. Remove C / C++ to let another extension such as clangd handle them
kxapp.swiftSourcekitLspBackgroundIndexingBackground indexing: auto / on / off
kxapp.swiftPathUse a different Swift toolchain; empty means the Xcode selected with xcode-select
kxapp.swiftSourcekitLspDisableTurn code completion off

Every setting for Swift code completion in VS Code is in VS Code shortcuts and settings for iOS app development. If completion never shows up, follow the steps in common iOS build errors in VS Code.

Frequently asked questions

Should I commit buildServer.json to Git?

No need; you can add it to .gitignore. The extension puts it in the project root the first time it opens the project.

I already use xcode-build-server. Can I switch to KXApp's completion?

Yes: delete the existing buildServer.json in the project root and reload the window. The extension never overwrites a file another tool created, so until you delete it, that tool keeps handling completion.

Why do I see "No such module" right after opening a project?

Because the libraries haven't been built yet. The extension builds once in the background and the error clears when that build finishes; you can also press Cmd+B yourself.

Can I use it together with clangd?

Yes, but both extensions will answer for C and Objective-C. Disable one, or remove C / C++ from kxapp.swiftSourcekitLspSupportedLanguages so clangd handles them.

Next steps