Swift packages are bundles of source files, binaries, and resources that you can reuse in your Xcode projects. In AppCode, you can work with Xcode projects that use Swift packages as well as with standalone 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|
After loading a project, AppCode will start syncing its dependencies declared in Package.swift. You can manually invoke the synchronization later by selecting from the main menu or from the context menu of the Project tool window:
General code assistance features (completion, highlighting, and navigation) that you have in a regular Xcode project are available for Swift packages as well.
Edit the package manifest file
When editing the Package.swift file in AppCode, you can use the target name and path completion:
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 in the top-right corner of the editor or press ⇧⌘I:
Run/debug Swift packages
AppCode automatically creates run/debug configurations for all products and test targets in the package manifest:
To run a Swift package or test, select its configuration in the list and press ⇧F10 or click on the toolbar. To start debugging, set breakpoints and press ⇧F9 or click . See more in Start the debugger session.
You can also run tests with coverage: select a test run/debug configuration and click . 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:
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 in the top left corner of the Run/Debug Configurations dialog and select Swift Package Run or Swift Package Test.
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:
When creating a Swift Package Test configuration, you need to select a test target in the Target field:
See more in Create run/debug configurations for tests.
To manage Swift package dependencies, select Swift Package Manager from the context menu or from the main menu. The following actions are available:
|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 new versions of remote dependencies.||Available for standalone Swift packages only.|
|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.|