Member-only story

Solving Swift Macro Trust Issues in Xcode Cloud Builds

Swift macros are powerful but can break your CI pipeline with trust errors. Learn how to implement a simple post-clone script that solves the “Target must be enabled” error in Xcode Cloud once and for all.

--

The Problem with Swift Macros in CI Environments

Swift macros, introduced in Xcode 15 with Swift 5.9, are a powerful feature that enables code generation and compile-time metaprogramming. While they offer excellent developer productivity benefits, they’ve introduced a new challenge for CI/CD pipelines, particularly in Xcode Cloud.

When you first use a macro locally, Xcode displays a dialog asking you to trust the macro’s package before it can be executed. This works fine on your development machine, but becomes problematic in automated environments like Xcode Cloud where there’s no way to click “OK” on a dialog box.

If you’ve tried to build a project using Swift macros in Xcode Cloud, you’ve likely encountered this frustrating error:

Target must be enabled before it can be used.

A Complete Solution

After some research, I’ve found a reliable solution that works consistently for Xcode Cloud builds using Swift macros. Here’s how to implement it:

Step 1: Create a CI Scripts Folder

First, let’s create a dedicated folder for our CI scripts:

  1. Right-click your project in Xcode
  2. Select “New Group”
  3. Name it ci_scripts

Step 2: Create the Post-Clone Script

Next, we’ll create a post-clone script that Xcode Cloud will automatically execute after cloning your repository:

  1. Right-click the ci_scripts folder
  2. Select “New File” → “Empty File”
  3. Name it ci_post_clone.sh

Step 3: Add the Script Content

--

--

Cihat Gündüz
Cihat Gündüz

Written by Cihat Gündüz

📱Indie iOS Developer, 🎬Content Creator for 👨🏻‍💻Developers. Apps: RemafoX, Twoot it!. More in the works.

No responses yet

Write a response