Build xcframework using Aggregated Targets in xcode.
Aggregated Targets is used when we need to build multiple targets together somehow.
you can give name like "AggregatedFramework" Change the scheme to "AggregatedFramework" Scheme and then edit scheme. Choose Run tab from the left panel then change the build configuration to release.
Go back and choose "AggregatedFramework" from the targets then choose Build Phases then click on the little + to add a dependency, and choose Grocerybag Framework Target.
Then click on the other + above Target dependancies word to add a New Run Script Phase
You can rename the script to what it will do, for example "Create Aggregated Framework"
Start typing in the script area or copy past from this sample project.
After script part ready choose the AggregatedTarget and run you project. Once it builds successfully check your project directory, you should be able to see a new directory named xcframework which contains your framework and if you look inside you should see both simulator and iphone architectures are in there.
if you received below error while build framework. "No 'swiftinterface' files found within ..."
Please follow below steps:
Project target-> Build settings-> BUILD_LIBRARY_FOR_DISTRIBUTION = YES Project target-> Build settings-> Skip Install = NO
Or
Select Framework from target like "Grocerybag" goto Build settings-> BUILD_LIBRARY_FOR_DISTRIBUTION = YES
and then again come back to AggregatedFramework tagrget and try to build.
OUTPUT:
Now you can darg and drop framework in your project and import when you needed. Check below image for reference:
For further learning you can check below Apple video: https://developer.apple.com/wwdc19/416