Skip to main content
On this page

Swift and Objective-C Code Completion on Windows in VS Code

Completion, go to definition and error checking for Swift, Objective-C and C/C++, ready as soon as you open the project. When you need to build once first, and what to do when completion misbehaves.

Last updated

Swift code completion on Windows needs no setup: install the KXBuild extension and open your project in VS Code to get completion, go to definition and error checking for Swift, Objective-C and C / C++, including the system framework APIs of the iOS SDK. You only need to build once when you import modules that other targets in the project produce. If suggestions go wrong, the Restart Code Completion and Re-Index Project commands bring them back.

Which files get Swift and Objective-C code completion on Windows?

FilesProvided by
.swiftBuilt into the extension. Starts the first time you open a Swift file.
.m .mm .h .c .cppThe clangd extension, installed alongside KXBuild

Don't run KXBuild's Swift support and the official Swift extension (swiftlang.swift-vscode) at the same time. If the official extension is installed, KXBuild steps aside and tells you once. To use KXBuild's completion, disable the official Swift extension in the Extensions view.

When do I need to build before code completion works?

Modules produced by other targets in the project, such as other frameworks or Swift packages, don't exist until they're built. Until then, imports of them show as not found. Build once and they resolve.

How do I fix missing or wrong code completion?

  1. Run KXBuild: Restart Code Completion. Use this too if you just installed the toolchain and the language server hasn't started.
  2. Run KXBuild: Re-Index Project after changing many files or switching branches.
  3. If a new file isn't recognized, make sure it's added to the project, then right-click the .xcodeproj in the Explorer and choose Generate compile_commands.json.
  4. Check Output > SourceKit Language Server, or Output > clangd for Objective-C.

Working through these steps in order fixes most problems and brings Swift code completion on Windows back to how it was when you opened the project. If the extension itself isn't set up yet, first install the VS Code iOS extension.

Next steps