[Solved] Swift Macros: external macro implementation type could not be found – Ios

by
Maya Patel
axios azure-pipelines swift-macro swift5.9 xcode15

Quick Fix: In the Xcode project’s build settings, ensure that the "macOS Support Version" for the SwiftSyntaxMacros target is set to a version that is compatible with the version of Xcode and macOS being used. For example, if using Xcode 14 and macOS 14, set the macOS Support Version to 12.

The Problem:

When using the MetaCodable macro in a Swift project, developers encounter the error message "external macro implementation type ‘CodableMacroPlugin.CodedAt’ could not be found for macro ‘CodedAt’". This issue arises specifically when building the project via Microsoft Azure’s Pipeline with a local machine as the run agent (e.g., MBP M1 Max – Sonoma – XCode 15). The problem persists despite attempts to add various flags to the "other Swift flags" in the build settings.

The Solutions:

Solution 1: Check the macOS Support Version

The issue with the error message “error: external macro implementation type ‘CodableMacroPlugin.CodedAt’ could not be found for macro ‘CodedAt'” might occur due to a mismatch between the macOS support version specified in your library and the macOS version running on the server where you’re building your project.

To resolve this problem, ensure that the macOS support version defined in your library matches the macOS version running on the server. In this particular scenario, the developer had to set the macOS support version to 12 to match the server’s macOS version 13.X.

By aligning the macOS support version with the server’s macOS version, the issue was resolved.

Here’s a code snippet demonstrating how to set the macOS support version in your library:

platforms: [.macOS(.v12), .iOS(.v15)],

This example sets the macOS support version to 12 and the iOS support version to 15. Adjust these versions according to your requirements.

By following these steps, you can potentially resolve the issue related to the external macro implementation type not being found.

Solution 2: Removing -sdk Flag

If your project runs smoothly in Xcode but you encounter this issue solely from an xcodebuild command or another CI pipeline tool, the culprit might be the -sdk flag (for example, -sdk iphonesimulator).

In such cases, simply removing the -sdk iphonesimulator flag from your xcodebuild command should resolve the problem.

Q&A

What cause this error "error: external macro implementation type ‘CodableMacroPlugin.CodedAt’ could not be found for macro ‘CodedAt’"

The error displays mainly because library supports a version of macOS higher than the one that’s running on the server

How to fix the error when using Xcodebuild command?

Remove "-sdk iphonesimulator" from Xcodebuild command

Video Explanation:

The following video, titled "How to Fix the 'Unhandled Exception Has Occurred' Error In ...", provides additional insights and in-depth exploration related to the topics discussed in this post.

Play video

... find module This tutorial will apply for computers, laptops, desktops ... That's because Windows does not know how to handle the exception.