A short guide on how to create a XCFramework to then use it in your Xcode projects.
The XCFramework format allows developers to conveniently distribute binary libraries for multiple platforms and architectures in a single bundle. For example, with XCFrameworks, vendors no longer need to merge (lipo) multiple architectures into a single binary, only to later have to remove the Simulator slice during the archive phase.
XCFrameworks require Xcode 11 or later and they can be integrated similarly to how we’re used to integrating the .framework format.
These instructions will help you generate a .xcframework
What things are needed to generate a .xcframework 😞
- Nothing fancy ... Just Xcode 🥳
-
(To rather perform each command manually, see 'Step By Step')
Here's how to download and run the script 🤓
Why?
• Because inside the repo there's a create-xcframework.sh file that you need.
What do I mean by the root of your project ?
• The same folder as the folder your .xcodeproj is in.
Why?
• We first need to edit it so that it knows what your framework's name is.
Open your terminal, make sure you're in the root of your project (where you placed the create-xcframework.sh
file) and run this command:
sh create-xcframework.sh
You can also run it with the following command:
chmod 755 create-xcframework.sh && ./create-xcframework.sh
....unless of course you changed the path variables in the create-xcframework.sh file 🤨
-
(To rather do all this automatically by running the script, see 'Download and Run The Script')
Here's how to run each command in your terminal manually 🤓
What do I mean by the root of your project ?
• The same folder as the folder your .xcodeproj is in.
We’ll be archiving for the iOS device, Simulator, and Mac Catalyst architectures. If you don't want one of these architectures supported by your xcframework, then just skip the step where we archive for that architecture.
Please refer to Download and Run The Script') if you want to see how to change from a workspace
to a project
.
Change MySexyFramework
to the name of your framework
xcodebuild archive -workspace 'MySexyFramework.xcworkspace' \
-scheme 'MySexyFramework.framework' \
-configuration Release \
-destination 'generic/platform=iOS' \
-archivePath './archives/MySexyFramework.framework-iphoneos.xcarchive' SKIP_INSTALL=NO
Change MySexyFramework
to the name of your framework
xcodebuild archive -workspace 'MySexyFramework.xcworkspace' \
-scheme 'MySexyFramework.framework' \
-configuration Release \
-destination 'generic/platform=iOS Simulator' \
-archivePath './archives/MySexyFramework.framework-iphonesimulator.xcarchive' SKIP_INSTALL=NO
Change MySexyFramework
to the name of your framework. Skip this step if you're not building Mac applications with this framework.
xcodebuild archive -workspace 'MySexyFramework.xcworkspace' \
-scheme 'MySexyFramework.framework' \
-configuration Release \
-destination 'platform=macOS,arch=x86_64,variant=Mac Catalyst' \
-archivePath './archives/MySexyFramework.framework-catalyst.xcarchive' SKIP_INSTALL=NO
Change MySexyFramework
to the name of your framework.
Include this line to the below command if you are building Mac applications with this framework.
-framework './archives/MySexyFramework.framework-catalyst.xcarchive/Products/Library/Frameworks/MySexyFramework.framework' \
xcodebuild -create-xcframework \
-framework './archives/MySexyFramework.framework-iphonesimulator.xcarchive/Products/Library/Frameworks/MySexyFramework.framework' \
-framework './archives/MySexyFramework.framework-iphoneos.xcarchive/Products/Library/Frameworks/MySexyFramework.framework' \
-output './archive/xcframework/MySexyFramework.xcframework'
....unless of course you changed the path variables in the create-xcframework.sh file 🤨
- Read up a bit more on xcframeworks
- Be cool and email me if you're really stuck
[email protected]
- Be even cooler and google a lot! Learn! Knowledge is some sexy stuff!!
- Phillip Ronald Jacobs - LinkedIn
This project is licensed under the GoWildAndShare License...hahaha!
-
Thank You Apple Docs
-
Thank You Google
-
Thank You Youtube
-
Thank You StackOverflow
-
Thank You WeThinkCode_
-
Thank You Me
-
Thank You Granny, Thank You Grandpa... OuwkkyY this is getting weird & emotional. Good luck lol.
-
And I really don't mind helping when you have a problem but try and google first.
-
Thank Youuu... byeeee!