CLion 2022.2 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, macOS, and Windows (see this blog post for details).

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

    Item

    Description

    Resolve Dependencies

    Resolve package dependencies. Dependencies are resolved automatically on project opening. You may also need to invoke this action if you want to update remote dependencies or if you have changed the manifest file.

    Update Dependencies

    Download the latest version of remote dependencies.

    Clean

    Delete package build artefacts.

    Generate Xcode Project

    Generate the .xcodeproj file in the root directory of the package.

  • 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 runApp actions execute or debug App actions start debugger such configurations using toolbar icons or by calling Run Anything (press Ctrl 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: 21 April 2022