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

Must use swift build before you can use language features

Before 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:

  1. Open the Command Palette with Cmd+Shift+P.
  2. Type “Tasks: Configure Default Build Task” and select it.
  3. Select “Create tasks.json file from template”, and then “Others”.
  4. Replace the content of the generated tasks.json file with the following:
{
    "version": "2.0.0",
    "tasks": [
        {
            "label": "swift build",
            "type": "shell",
            "command": "swift build",
            "group": {
                "kind": "build",
                "isDefault": true
            },
            "presentation": {
                "reveal": "always"
            },
            "problemMatcher": []
        }
    ]
}

This task will run the swift build command whenever you run the Build Task (Cmd+Shift+B).

2 items under this folder.