I am exploring the usage of Swift Macro in my CocoaPods-integrated project. I have successfully created a custom macro by following the instructions, and it functions properly in the host project. However, in the Pods
project, I am unable to import CustomMacro
for all the frameworks and development pods.
At this point, I am curious if there is a workaround that supports both CocoaPods and Swift Package Macro.
And also I found a Github thread discussing about a similiar topic: https://github.com/CocoaPods/CocoaPods/issues/11942 , but there’s no further conclusion.
So please help to give some advises about how to use Swift Macro in CocoaPods project if you have any experience.
2
Answers
Inspired by @Soumuya Mahunt and some other post and discussion, I successfully integrate the Swift Macro to a CocoaPods managed project and its all pods. All the details and steps can be found in this blog or the demo project.
The macro pod can be easily used by a project target or a development pod target.
For a development pod target or remote pod target, there would be some tricks to make it possible, add the following
post_install
script in thePodfile
will be fine.Please see the blog for detail.
If you want to distribute your macro library with CocoaPods, you have to build the macro target as an executable and provide that to the app/user target as:
I have written a step-by-step detailed article on this here. You can also see this in action as part of my MetaCodable library.