Swift in Visual Studio Code
Swift is a general-purpose programming language that's approachable for newcomers and powerful for experts. It is fast, modern, safe, and a joy to write. This topic goes into detail about setting up and using Swift within Visual Studio Code, with the swiftlang.swift-vscode extension.
The Swift extension includes:
- Syntax highlighting and code completion
- Code navigation features such as Go to Definition and Find All References
- Refactoring and quick fixes to code
- Package management and tasks with support for Swift Package Manager
- Rich support for debugging
- Testing with XCTest or Swift Testing frameworks
The Swift extension is designed to support the following projects:
- Swift Package Manager projects (e.g. using a
Package.swift) - Projects that can generate a
compile_commands.json(e.g. using CMake)
Install the extension
- First, install Swift. If you do not already have Swift installed on your system, see the Getting Started Guide on Swift.org.
- Download and install Visual Studio Code.
- Install the Swift extension from the VS Code Marketplace or directly from within the VS Code extensions pane.

Create a new Swift project
To create a new Swift project, you can use the Swift: Create New Project... command in
the Swift extension to guide you through the process. You can find this command by opening
the Command Palette and following the instructions below.
- For macOS: CMD+Shift+P
- Other platforms: Ctrl+Shift+P

- Choose the type of project you'd like to create from the list of templates.
- Choose the directory where the project will be stored.
- Give your project a name.
- Open the newly created project. You will be prompted to open the project in
the current window, a new window, or add it to the current workspace. The
default behavior can be configured by using the
swift.openAfterCreateNewProjectsetting.
Language features
The Swift extension uses SourceKit LSP to power language features. SourceKit LSP provides the following features in the editor. Use these links to see the VS Code documentation for each topic:
SourceKit LSP also provides code actions to automate common tasks. Code actions in VS Code appear as a light bulb near the editor margin (see the below screenshot for an example of this). Clicking on the light bulb will show you the available actions which can include: