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?
| Files | Provided by |
|---|---|
| .swift | Built into the extension. Starts the first time you open a Swift file. |
| .m .mm .h .c .cpp | The 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?
- Run KXBuild: Restart Code Completion. Use this too if you just installed the toolchain and the language server hasn't started.
- Run KXBuild: Re-Index Project after changing many files or switching branches.
- 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.
- 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
Run and debug
Three ways to start (Build & Run, Run and Attach), what you see if a step fails after F5, panels and output during a debug session, launch.json fields and Dart debugging for Flutter.
Project Settings Editor
No need to open project.pbxproj. Change identity, deployment, signing and version on the General page, and view and edit Build Settings by Basic, Customized, All and by level, with resolved values shown live.