xcframeworks repo
This is a demonstration of creating and integrating the xcframeworks and their co-op with static libraries and Swift packages within the same Xcode project.
Table of contents
Prerequisites
- Xcode 11 and above (Xcode 15 and above recommended - signed xcframeworks, privacy manifests)
- Swift 5.1 and above
- Github/Gitlab/Bitbucket account set in Xcode’s account preferences
Changelog
| What’s new |
Xcode version |
Swift version |
Description |
| Module stable binaries |
Xcode 11 |
Swift 5.1 |
Library evolution allows the library authors to distribute module stable Swift binaries |
| New version of .swiftinterface interface |
Xcode 11.4 |
Swift 5.2 |
New annotations added to Swift @_inheritsConvenienceInitializers, @_hasMissingDesignatedInitializers. ⚠️ Module interfaces aren’t backwards compatible, clients using Swift 5.1.3 and below won’t be able to compile Swift binaries compiled with Swift 5.2. More info here |
| Support for binary dependencies in SwiftPM |
Xcode 12.0 |
Swift 5.3 |
Swift Package Manager now supports declaring binary targets in Package.swift |
| Debug symbols |
Xcode 12.0 |
Swift 5.3 |
Debug symbols (dSYMs, BCSymbolMaps) can be included within the xcframework through new -debug-symbols <absolute path> flag |
| Bitcode deprecated |
Xcode 14.0 |
Swift 5.7 |
Bitcode is deprecated & App Store no longer accepts bitcode submissions. BCSymbolMaps are no longer needed |
| Signed xcframeworks |
Xcode 15.0 |
Swift 5.9 |
Xcode verifies the code signature of xcframeworks & remembers the signing identity. If the identity changes, the build fails |
| Privacy manifests |
Xcode 15.0 |
Swift 5.9 |
Xcframeworks can ship PrivacyInfo.xcprivacy. Required (+ signature) for commonly used 3rd party SDKs since May 2024 |
| Mergeable libraries |
Xcode 15.0 |
Swift 5.9 |
Dynamic frameworks built with MERGEABLE_LIBRARY=YES can be merged into the app binary in release builds |
| visionOS |
Xcode 15.2 |
Swift 5.9 |
xcframework can contain visionOS & visionOS Simulator slices |
Requirements
- Xcode11
- Swift 5.1 and above
Motivation & consequences
-
introduce standard format to gain module stability for your Swift frameworks & libraries. Library author & client of a library are no longer required to use the same version of compiler. Please note, that the module stable interfaces are only forward-compatible
-
provide seamless experience when creating & integrating the module stable frameworks
-
support all Apple platforms and architectures
-
STOP creating & using fat dynamic frameworks. (library author) - lipo can’t put arm64 device & arm64 simulator (Apple Silicon) slices into one binary anyway.
-
STOP slicing frameworks by stripping the architectures in your projects’ targets’ custom build-phase. (integrator)
flowchart LR
subgraph fat["❌ fat framework (lipo)"]
F1["arm64 (device)"]
F2["x86_64 (simulator)"]
F3["arm64 (simulator)<br/>doesn't fit - arm64 is already taken"]
end
subgraph xc["✅ xcframework"]
X1["ios-arm64<br/>(device)"]
X2["ios-arm64_x86_64-simulator<br/>(simulator)"]
end
Contents of xcframework
This format bundles module-stable frameworks (.swiftinterface) for the platforms of interest.
The Info.plist contains all available frameworks in a bundle specified by library identifiers. This information is used by Xcode during the linking time => xcodebuild picks the right framework for the platform we’re building against.
Since Xcode 12.0 the xcframework can contain also debug symbols (dSYMs, BCSymbolMaps).
Simplified, this is what happens when you build your app:
flowchart LR
App["Your app<br/>building for iPhone"] --> Plist["Info.plist<br/>inside .xcframework"]
Sim["Your app<br/>building for Simulator"] --> Plist
Plist -->|device| D["ios-arm64/<br/>My.framework"]
Plist -->|simulator| S["ios-arm64_x86_64-simulator/<br/>My.framework"]
The structure of xcframework looks as shown below

Size of xcframework
During my tests I realized, the size of an xcframework was smaller than the size of an corresponding fat framework. I tested swift only & mixed frameworks.
Generally the lipo commandline tool adds a bit of overhead for all contained architectures.
xcframework supports all Apple platforms & their variants - iOS, maccatalyst, macOS, tvOS, watchOS, visionOS, DriverKit.
iPadOS & carPlayOS are built with iOS SDK, so they are covered by the iOS & iOS Simulator slices.
List of destinations
| Platform |
Destination |
| iOS |
generic/platform=iOS |
| iOS Simulator |
generic/platform=iOS Simulator |
| maccatalyst |
generic/platform=macOS,variant=Mac Catalyst |
| macOS |
generic/platform=macOS |
| tvOS |
generic/platform=tvOS |
| tvOS Simulator |
generic/platform=tvOS Simulator |
| watchOS |
generic/platform=watchOS |
| watchOS Simulator |
generic/platform=watchOS Simulator |
| visionOS |
generic/platform=visionOS |
| visionOS Simulator |
generic/platform=visionOS Simulator |
| DriverKit |
generic/platform=DriverKit |
Tip: xcodebuild -showdestinations -scheme MyScheme lists destinations supported by your scheme.
This section describes the process of creating the xcframework by archiving & creating the final xcframeworks from 2 archives built for iOS & iOS Simulator.
However, if you’re not interested in the details of the process of how the xcframework is created, head directly to section: Create xcframework using fastlane plugin.
flowchart LR
Scheme["MyScheme"] -->|"xcodebuild archive<br/>generic/platform=iOS"| A1["MyScheme-iOS.xcarchive"]
Scheme -->|"xcodebuild archive<br/>generic/platform=iOS Simulator"| A2["MyScheme-iOS-Simulator.xcarchive"]
A1 --> C["xcodebuild -create-xcframework"]
A2 --> C
C --> X["My.xcframework"]
1.1 Pass SKIP_INSTALL=NO && BUILD_LIBRARY_FOR_DISTRIBUTION=YES to archive your scheme
xcodebuild archive \
-workspace MyWorkspace.xcworkspace \
-scheme MyScheme \
-destination "generic/platform=iOS" \
-archivePath "archives/MyScheme-iOS" \
SKIP_INSTALL=NO \
BUILD_LIBRARY_FOR_DISTRIBUTION=YES
1.2 iOS Simulator - archive your scheme for iOS Simulator platform by specifying correct destination destination="generic/platform=iOS Simulator" & point archivePath to architecture specific path, e.g. archives/MyScheme-iOS-Simulator. Generic destination builds all simulator archs (arm64 + x86_64).
xcodebuild archive \
..
-destination "generic/platform=iOS Simulator" \
-archivePath "archives/MyScheme-iOS-Simulator" \
..
1.3 iOS - archive your scheme for iOS by specifying destination="generic/platform=iOS" & point archivePath to device specific path. The architecture specific path will ensure the archive from step 1.2 won’t be overwritten, e.g. MyScheme-iOS
xcodebuild archive \
..
-destination "generic/platform=iOS" \
-archivePath "archives/MyScheme-iOS" \
..
Locations
Binaries in .xcarchive are located under:
Products/Library/Frameworks folder for dynamic frameworks
Products/usr/local/lib folder for static libraries
dSYMs folder for debug symbols
2. Create .xcframework from built archives
xcodebuild allows you to create xcframework by specifying frameworks, libraries or even can add headers to the libraries.

1. Specify all frameworks or libraries that you want to add into .xcframework
2. Specify the output path using -output argument. Don’t forget to add .xcframework extension to your output path.
# -debug-symbols (Xcode 12.0+) belongs to the -framework before it & needs an absolute path to the .dSYM
xcodebuild -create-xcframework \
-framework archives/MyScheme-iOS.xcarchive/Products/Library/Frameworks/My.framework \
-debug-symbols "$PWD/archives/MyScheme-iOS.xcarchive/dSYMs/My.framework.dSYM" \
-framework archives/MyScheme-iOS-Simulator.xcarchive/Products/Library/Frameworks/My.framework \
-debug-symbols "$PWD/archives/MyScheme-iOS-Simulator.xcarchive/dSYMs/My.framework.dSYM" \
-output My.xcframework
For static libraries use -library (Objective-C libraries also need -headers <path to public headers>):
xcodebuild -create-xcframework \
-library archives/MyLib-iOS.xcarchive/Products/usr/local/lib/libMyLib.a \
-library archives/MyLib-iOS-Simulator.xcarchive/Products/usr/local/lib/libMyLib.a \
-output MyLib.xcframework
⚠️ Swift static libraries: the archive contains only the .a, without the .swiftmodule, so clients get No such module 'MyLib' (#1).
Copy the .swiftmodule next to the .a right after each archive (next archive wipes the ArchiveIntermediates folder) - -create-xcframework picks it up from there:
cp -r <derivedDataPath>/Build/Intermediates.noindex/ArchiveIntermediates/MyLib/BuildProductsPath/Release-iphoneos/MyLib.swiftmodule \
archives/MyLib-iOS.xcarchive/Products/usr/local/lib/
flowchart LR
subgraph before["archive gives you"]
B1["libMyLib.a"]
end
subgraph after["xcframework slice needs"]
A1["libMyLib.a"]
A2["MyLib.swiftmodule<br/>(.swiftinterface)"]
end
before -->|"copy .swiftmodule<br/>from derived data"| after
scripts/create_xcframeworks.sh does exactly this for the StaticLibrary in this repo.
Module stability is gained with Xcode 11 + Swift 5.1, once your module declares .swiftinterface file, that describes the public interface of your framework along with linker flags, used toolchain and other info. Swift interface can be found under your framework’s swiftmodule folder.
.swiftinterface file is autogenerated by the compiler when you archive with BUILD_LIBRARY_FOR_DISTRIBUTION=YES.

Create xcframework using fastlane plugin
This plugin allows you to generate the xcframework (including all dSYMs) by specifying the desired destinations.
E.g. destination [iOS] will generate xcframework that contains slices for both iOS & iOS Simulator.
⚠️ Currently the plugin doesn’t support static libraries.
⚠️ The plugin (v1.1.2) enables bitcode by default. Bitcode is deprecated since Xcode 14, so pass enable_bitcode: false.
- Add plugin to your project
fastlane add_plugin create_xcframework
- Add lane to your
Fastfile
desc "Export xcframework"
lane :export_xcframework do
create_xcframework(
workspace: 'path/to/your.xcworkspace',
scheme: 'name of your scheme',
destinations: ['iOS', 'maccatalyst'],
enable_bitcode: false,
xcframework_output_directory: 'Products/xcframeworks'
)
end
NOTE:
Version 1.1.0 of the fastlane plugin includes support for debug symbols.
You can try out the plugin in this project by calling following command:
bundle exec fastlane export_xcframework
How to create .xcframework from Swift Package
xcodebuild can archive Swift Package schemes directly, without the Xcode project (#14, #19). There are few gotchas though:
flowchart LR
P["Package.swift<br/>type: .dynamic"] -->|xcodebuild archive| F["MyPackage.framework<br/>❌ no Modules folder"]
DD["DerivedData<br/>MyPackage.swiftmodule"] -->|"copy right after<br/>each archive"| F2["MyPackage.framework<br/>✅ Modules/MyPackage.swiftmodule"]
F --> F2
F2 -->|"-create-xcframework"| X["MyPackage.xcframework"]
- Make the library product dynamic, otherwise the archive contains just object files instead of a framework:
.library(name: "MyPackage", type: .dynamic, targets: ["MyPackage"])
- Archive the package scheme from the package directory (same flags as above):
xcodebuild archive \
-scheme MyPackage \
-destination "generic/platform=iOS" \
-archivePath "archives/MyPackage-iOS" \
-derivedDataPath .build/DerivedData \
SKIP_INSTALL=NO \
BUILD_LIBRARY_FOR_DISTRIBUTION=YES
Repeat for generic/platform=iOS Simulator.
- The framework lands in
Products/usr/local/lib/MyPackage.framework (not in Library/Frameworks), without the Modules folder - so the clients can’t import MyPackage. Copy the .swiftmodule (contains .swiftinterface) from the derived data into the framework right after each archive - the next archive wipes the ArchiveIntermediates folder:
FRAMEWORK=archives/MyPackage-iOS.xcarchive/Products/usr/local/lib/MyPackage.framework
mkdir -p "$FRAMEWORK/Modules"
cp -r .build/DerivedData/Build/Intermediates.noindex/ArchiveIntermediates/MyPackage/BuildProductsPath/Release-iphoneos/MyPackage.swiftmodule "$FRAMEWORK/Modules/"
Use Release-iphonesimulator for the simulator archive.
- Create the xcframework from the 2 frameworks the same way as in step 2, just point
-framework to Products/usr/local/lib/MyPackage.framework.
Tested with Xcode 27 - the client package consuming the xcframework via binaryTarget(path:) builds for both iOS & iOS Simulator.
⚠️ Resources (Bundle.module) of the package are generated into separate MyPackage_MyPackage.bundle & aren’t part of the framework, so you’ll need to ship them along.
Testing & Troubleshooting
Make sure to always build & run your generated xcframework before distributing it to your clients.
Few of the problems will unveil just at the compile or run time, so don’t rely solely on the success of the xcframework creation.
Here’s the list of compiler errors I got across when integrating built xcframework into Xcode project.
| Problem |
Severity |
Description |
Solution |
Redundant conformance of x to NSObjectProtocol |
error - thrown at dynamic linking time |
Your class is already subclassed from NSObject, which conforms to NSObjectProtocol |
Check protocol conformances of your classes and remove redundant conformance to NSObjectProtocol |
| Use of unimplemented initializer ‘init()’ for class |
error - thrown at dynamic linking time |
Objective-C ABI public classes need to provide public init |
Provide public init override for your public class: override public init() |
@objc’ class method in extension of subclass of Class X requires iOS 13.0.0 |
error |
Rules for interoperability with Objective-C has changed since iOS 13.0.0. and currently doesn’t support @objc interoperability in class extensions. There’s open question on Swift forums |
Move/Remove @objc declaration from your Swift class extension |
| scoped imports are not yet supported in module interfaces |
warning |
Read more about Swift import declarations here: https://nshipster.com/import/ |
Import the module instead of specific declaration. For example: change import class MyModule.MyClass to import MyModule |
| Can’t use framework compiled with Swift 5.2 in Swift 5.1.3 project |
error - thrown at linking time |
The xcframework was generated using the Swift 5.2 and above. Module stable interfaces are not backwards-compatible. |
Update your Xcode to Xcode 11.4 and above or generate module stable binary using Xcode 11.3 and below |
| Incompatible module |
error - thrown at linking time |
The module built for iOS Simulator shares the same arch slice as the new M1. |
Exclude arm64 slice when building your xcframework by specifying following build setting: EXCLUDED_ARCHS[sdk=iphonesimulator*] = arm64 Outdated workaround - it breaks the simulator builds on Apple Silicon Macs. Remove EXCLUDED_ARCHS & archive with generic/platform=iOS Simulator, so the simulator slice contains both arm64 & x86_64 |
| The signature of “X.xcframework” cannot be verified |
error |
Xcode 15+ verifies the xcframework signature. Content of xcframework was changed after signing (e.g. .DS_Store) or vendor’s signing identity has changed |
Vendor: sign the final xcframework codesign --timestamp -s "<identity>" My.xcframework & don’t touch it afterwards. Integrator: accept the identity change in the Issues navigator if it’s expected |
| Bitcode related errors |
error / warning |
Bitcode is deprecated since Xcode 14 |
Build with ENABLE_BITCODE=NO (enable_bitcode: false in the fastlane plugin) |
| No such module ‘MyStaticLib’ (#1) |
error - thrown at compile time |
Archive of a Swift static library doesn’t contain the .swiftmodule |
Copy the .swiftmodule next to the .a before creating the xcframework - see Create .xcframework from built archives |
No such module ‘X’ inside the .swiftinterface (#13) |
error - thrown at compile time |
Your framework publicly uses another module (e.g. a CocoaPod). The xcframework doesn’t contain its dependencies, so the client has to have module X too |
Ship the dependency as its own xcframework (built with BUILD_LIBRARY_FOR_DISTRIBUTION=YES) or hide it - internal import X (Swift 6) / @_implementationOnly import X - and don’t expose its types in your public API |
| A library with the identifier “ios-x86_64-maccatalyst” already exists (#8) |
error - thrown by -create-xcframework |
You passed 2 frameworks for the same platform, e.g. archive path was overwritten or same archive was passed twice |
Use separate -archivePath for every destination & pass each platform only once |
| xcframework is huge, e.g. 500 MB per slice (#15) |
- |
Mostly debug info & bitcode. Static libraries also carry all object code - only the used part ends up in the app |
Build without bitcode, keep debug symbols in dSYMs (DEBUG_INFORMATION_FORMAT=dwarf-with-dsym) and strip the binary. The xcframework size isn’t the size added to the app |
Distribution of xcframeworks
flowchart TD
X["My.xcframework"] --> M["Manually<br/>drag & drop"]
X --> SPM["Swift Package Manager ✅<br/>zip + checksum + binaryTarget"]
X --> CP["CocoaPods ⚠️<br/>trunk read-only from Dec 2, 2026"]
X --> C["Carthage<br/>0.38.0+"]
Manual integration is still the simplest option - no dependency manager needed. These days Swift Package Manager is the preferred way to distribute xcframeworks.
How to integrate .xcframework in your project
- Drag & drop .xcframework manually into your project’s target

- Embed & sign .xcframework in your project’s target (static library →
Do Not Embed)

What’s in XCFrameworks workspace
XCFrameworks workspace consists of:
-
StaticLibrary project - represents static library project
-
DynamicFramework project - represents project that builds dynamic framework
-
Swift Package - Swift Package for internal development (within Sample project)
-
TextAttributes - external Swift Package
-
Sample - Sample project that includes all of the dependencies mentioned above.

Materials
Binary Frameworks in Swift
https://developer.apple.com/videos/play/wwdc2019/416/
Distribute binary frameworks as Swift packages
https://developer.apple.com/wwdc20/10147
https://developer.apple.com/documentation/xcode/distributing-binary-frameworks-as-swift-packages
https://developer.apple.com/documentation/xcode/creating-a-multi-platform-binary-framework-bundle
Verify app dependencies with digital signatures (WWDC23)
https://developer.apple.com/wwdc23/10061
Meet mergeable libraries (WWDC23)
https://developer.apple.com/wwdc23/10268
Privacy manifest files
https://developer.apple.com/documentation/bundleresources/privacy-manifest-files
ABI Stability & Module Stability - swift.org
https://www.swift.org/blog/abi-stability-and-more/
Library evolution in Swift - swift.org
https://www.swift.org/blog/library-evolution/
Library evolution for stable ABIs
https://github.com/swiftlang/swift-evolution/blob/main/proposals/0260-library-evolution.md
Library evolution - Docs
https://github.com/swiftlang/swift/blob/main/docs/LibraryEvolution.rst
Alexis Beingessner - How Swift Achieved Dynamic Linking Where Rust Couldn’t
https://faultlore.com/blah/swift-abi/
Alex Grebenyuk - XCFrameworks (case-study about Distribution of xcframeworks as Swift Packages for specific case)
https://kean.blog/post/xcframeworks-caveats
评论