AppCode 2023.1 Help

Swift packages

Swift packages are bundles of source files, binaries, and resources that you can reuse in your projects. In AppCode, you can work with Xcode projects that use Swift packages as well as with standalone Swift packages.

Open Swift packages

When you try to open a Swift package or an Xcode project with Swift package dependencies from an unknown source for the first time, AppCode displays a warning and lets you decide whether to trust the project or open it in safe mode. See more in Project security.

All Swift packages and dependencies are available from the Project tool window:

Standalone Swift package

Xcode project

Standalone SPM in the Project tool window
SPM in the Project tool window

After loading a project, AppCode will start syncing its dependencies declared in Package.swift. You can manually invoke the synchronization later by selecting Tools | Swift Package Manager | Resolve Dependencies from the main menu or Swift Package Manager | Resolve Dependencies from the context menu of the Project tool window:

Swift SPM context menu

General code assistance features (completion, highlighting, and navigation) that you have in a regular Xcode project are available for Swift packages as well.

Create a new Swift package

In AppCode, you can create standalone Swift packages using the New Project wizard:

  1. From the main menu select File | New Project or click the New Project button from the Welcome screen.

  2. Select Multiplatform| Framework & Library | Swift Package and click Next:

    New Swift Package
  3. On the next page, type the package name and click Finish:

    Swift Package Name
  4. In the dialog that opens select a folder where the new package will be created and click Open Project.

AppCode will create an empty Swift package project and default run/debug configurations for the library and tests:

New project

Edit the package manifest file

When editing the Package.swift file in AppCode, you can use the target name and path completion:

Target name completion in Packages.swift

Every time you edit the manifest file, the structure of the Swift Package Manager project changes, and you need to load these changes to AppCode. To do this, click the Reload SPM Changes in the top-right corner of the editor or press ⇧⌘I:

Load SPM changes

Run/debug Swift packages

AppCode automatically creates run/debug configurations for all products and test targets in the package manifest:

Standalone SPM run configurations

To run a Swift package or test, select its configuration in the list and press Shift+F10 or click the Run button on the toolbar. To start debugging, set breakpoints and press Shift+F9 or click the Debug button.See more in Start the debugger session.

You can also run tests with coverage: select a test run/debug configuration and click the Run with Coverage button. See more in the Code coverage section.

To edit a run/debug configuration, click Edit Configuration in the run/debug configurations selector. In the dialog that opens, select the configuration that you want to edit:

Swift package run/debug configuration

Here you can specify a working directory, program arguments, and environment variables. In the Before launch section, you can set up the actions that should be executed prior to launching the run/debug configuration, for example, opening some link in a web browser. See more in the Run/debug configurations section.

To create a new run/debug configuration for a Swift package or Swift package test, click the App general add in the top left corner of the Run/Debug Configurations dialog and select Swift Package Run or Swift Package Test.

Create new SPM run/debug configuration

To create a configuration from the Swift Package Run template, you have to specify a target and executable in the corresponding fields. AppCode will suggest you the lists of targets and executables available in the manifest file:

Select an SPM target

When creating a Swift Package Test configuration, you need to select a test target in the Target field:

Select the test target

See more in Create run/debug configurations for tests.

Manage dependencies

To manage Swift package dependencies, select Swift Package Manager from the context menu or Tools | Swift Package Manager from the main menu. The following actions are available:

Item

Description

Note

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.

Available for standalone Swift packages only.

Generate Xcode Project

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

Available for standalone Swift packages only.

Last modified: 07 March 2023