Distribute your code as XCFramework

Set up the project

To set up your project for creating an XCFramework, ensure your Xcode project has a scheme that builds only the framework target and its dependencies.

Configure these build settings on your target:

For more information, see Customizing the build schemes for a project and Configuring the build settings of a target.

Create archives for frameworks or libraries and Generate the XCFramework bundle

Create an archive of your framework or library for each platform you wish to support by running xcodebuild in Terminal using the archive build action.

The following command archives a framework for the iOS platform:

SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null && pwd )"

cd "$SCRIPT_DIR"/../

rm -rf MyFramework.xcframework
rm -rf "${SCRIPT_DIR}"/../archives

xcodebuild archive \
    -project MyFramework.xcodeproj \
    -scheme MyFramework \
    -destination "generic/platform=iOS" \
    -archivePath "$PWD/archives/MyFramework" \
    SKIP_INSTALL=NO \
    BUILD_LIBRARY_FOR_DISTRIBUTION=YES | xcbeautify

xcodebuild archive \
    -project MyFramework.xcodeproj \
    -scheme MyFramework \
    -destination "generic/platform=iOS Simulator" \
    -archivePath "$PWD/archives/MyFramework-Simulator" \
    SKIP_INSTALL=NO \
    BUILD_LIBRARY_FOR_DISTRIBUTION=YES | xcbeautify

xcodebuild -create-xcframework \
    -framework "Archives/MyFramework.xcarchive/Products/Library/Frameworks/MyFramework.framework" \
    -debug-symbols "$PWD/archives/MyFramework.xcarchive/dSYMs/MyFramework.framework.dSYM" \
    -framework "Archives/MyFramework-Simulator.xcarchive/Products/Library/Frameworks/MyFramework.framework" \
    -debug-symbols "$PWD/archives/MyFramework-Simulator.xcarchive/dSYMs/MyFramework.framework.dSYM" \
    -output "${SCRIPT_DIR}"/../MyFramework.xcframework

rm -rf "${SCRIPT_DIR}"/../archives