You can write and build Swift code in index. Make sure to download the official Swift extension inside of VS Code.
Use Cases
Demo
Docs
-
Tasks in Visual Studio Code The VS Code 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:
Must use
swift build
before you can use language featuresBefore language features can be used you must perform a
swift build
command on your project either on the command line or using a task in VS Code. This populates the index in SourceKit-LSP.
How to build
To build Swift code in Visual Studio Code, you need to set up a task that will run the Swift compiler. Here’s how you can do it:
- Open the Command Palette with
Cmd+Shift+P
. - Type “Tasks: Configure Default Build Task” and select it.
- Select “Create tasks.json file from template”, and then “Others”.
- Replace the content of the generated
tasks.json
file with the following:
This task will run the swift build
command whenever you run the Build Task (Cmd+Shift+B
).