Recently, I came into the framework development and I’ve learned or say went through lots of things during development like dependency free framework, swift version compatible issue, active architecture build problem, create private framework with cocoapod, method swizzling, threading etc etc
In this article, I’ll try to explain how I went through multiple articles for fat framework creation along with multiple swift version compatibility issues and later how I figured out device architecture problem during upload.
What is fat or universal framework?
In framework development, when we build our framework it will create two versions of .framework file as below
- For Device i.e armv7, armv7s, arm64 (
In Debug-iphoneos dir)
- For Simulator i.e x86_64, i386 (
In Debug-iphonesimulator dir)
After combining above two versions of the framework the resulting framework is called
universal static framework or library.
NOTE: x86_64, i386 are not valid device architecture, means it will gonna fail during build upload or build validation process.
Step to create a fat framework as below Reference
- Create a new (Aggregate) target in your framework’s project (
In Xcode 7 and 8, click File>New>Target... and there select "Other" group to select Aggregate target)
- Under “Build Phases” select “Add Run Script” and copy the contents of below script
- Select the Aggregate target in the Scheme Selection drop down
- Build the target for the aggregate scheme
Now as per above script final .framework file is valid for all available architecture i.e x86_64, i386, armv7, armv7s, arm64
You can check framework valid architecture via running below command on terminal
The output you will see:
Architecture in the fat file: framework_name are: x86_64 i386 armv7 armv7s arm64
Means your .framework will be available for both simulator as well as device architecture!!
Secondly, now I’m facing swift compatibility issues for the above-created framework as my framework based on swift 4.2 only
Below is the conditional #if statement I have used in some part of code Reference
Now to make it available for multiple swift version you have to build using a different command like Toolchain through Xcode
- First, download and install swift Toolchain via below link
After above package installation jump to
Xcode->Preference->Component->Toolchainand select your swift version
Also change the swift version in Build Settings same as what you selected in Toolchain
Finally, build it using manually created fat aggregate target and check your ‘build’ output directory as per our above fat framework script, you will see .framework file for all architecture along with selected swift version.
NOTE: If you are not using cocoapod or carthage for your framework as dependency platform then only most of the time you will face kind of below issue.
Now we have to make it available for device architecture only otherwise you will face such issue on host app during app store upload.
Because Apple won’t allow x86_64, i386 architecture on app store build.
So for wrapping out x86_64, i386 architecture from framework on host app (App in which our fat framework is in use) use below script Reference
Under “Build Phases” select “Add Run Script” and copy the contents of below script
Once you add above script it will wrap out all invalid architecture via looping through all imported frameworks and host app won’t face architecture related issue during their final upload on the store.