Xcode

You can integrate Packmind CLI in the build phase of your Xcode projects, to get violations of your Packmind practices in your source code.

Due to the limitations offered by Xcode, the experience is limited in comparison with other supported IDEs.

However, the core feature β€”Detectionβ€” is fully available, ensuring you can use Packmind to detect best practices directly within your workflow.

What you'll get is the results of the execution of the Packmind CLI, that will display warnings when it detect violations of your practices.

Step 1: Install the Packmind CLI

You can refer to the dedicated documentation here.

Packmind CLI

The easiest remains is to install the npm package globally with:

npm install -g packmind-cli

Ensure NodeJS is setup on your MacOS. If not, you can get started with the following link to install Node 20.

To ensure all is setup correctly, please use

packmind-cli -v

and ensures it returns a proper version number.

Ensure to have at least 1.8.4, as Xcode support was introduced in the version

Step 2: Configure your Xcode project

Directly in your Xcode project, add a custom Build Phase using the '+' button.

We recommend to use bin/zsh as the shell, as it's the standard for MacOS. Note that the first instruction allows the script to load your environment variables and especially the NodeJS executable.

Here is this script shown in the screen:

. ~/.zshrc
cd "${SRCROOT}"
packmind-cli scan --formatters xcode --spaces="Swift,Space 2" --mode onlyChanged
exit 0

Here we use the --spaces="Swift,Space 2" option, but you need to adapt it to your context by adding the name of the space or spaces (separated with a ",") you want to use for the detection.

You can add your API Key in your.zshrcfile, it should contain the following line:

export PACKMIND_API_KEY=<your_api_key>

You can retrieve your API key from the Web interface of Packmind, in the My account > API Key and addons menu.

Based on your context and project's setup, you can adjust this script. What's required is:

  • To be able to run the CLI

  • To load as an environment variable an API Key to authenticate to Packmind.

You can read the CLI documentation to adjust the settings.

Step 3: Allow the script to read your project files

The last step is to ensure the User Script Sandboxing is properly set within the Build Settings.

Select All and Levels and search "sandbox".

You should set the value to No, at least for the Debug phase. Otherwise, you're likely to get errors such as permissions issues to read your current directory.

Now, when you'll build your project, the CLI will be run and displays warnings for the results.

Last updated

Was this helpful?