CLion 2020.1 Help

Swift

Swift is supported in CLion via the Swift plugin. With this plugin installed and enabled, CLion can be used as a fully-functional Swift IDE on Linux and macOS.

Enable Swift support

  1. In Settings/Preferences | Plugins, search for Swift and install the Swift plugin:

    Swift plugin installation

  2. Download and install the Swift toolchain.

  3. Go to Settings/Preferences | Build, Execution, Deployment | Swift and set the path to the Swift toolchain:

    Swift toolchain settings

Create a new Swift Package project

  1. Go to File | New Project and select the Swift Package project type:

    new Swift Package project

  2. Specify the project's name and package type (Executable, Library, or System).

  3. The Swift version is detected according to the toolchain provided in Settings/Preferences | Build, Execution, Deployment | Swift.

    Click Configure to open the settings dialog and change the path if required.

Swift support in CLion includes the following features:

  • Automatic resolve for project dependencies:

    sync project dependencies

  • Swift Package Manager actions available from the Tools | Swift Package Manager menu:

    Swift Package Manager actions
  • Detecting and importing changes:

    import changes

  • Code highlighting and completion in .swift files including completion for project targets in Package.swift:

    completion for project targets

  • Code generation Alt+Insert and refactoring Ctrl+Alt+Shift+T options:

    Generate and Refactor This actions

  • Swift-specific code checks including SourceKit inspections (to configure the inspections, go to Settings/Preferences | Editor | Inspections | Swift):

    Swift code inspections

Run/debug configurations for Swift

CLion automatically creates run/debug configurations for all products listed in the Package.swift file:

run/debug configurations

To create or edit configurations, go to the Edit Configurations dialog:

run/debug configuration settings

You can runicons actions execute or debug icons actions startDebugger such configurations using toolbar icons or by calling Run Anything (press ^ twice). All CLion debugging features will be available for your Swift configurations. To help you work in Swift LLDB console, CLion provides completion for the debugger commands.

Last modified: 11 June 2020