Framework in ios and Publish on the cocoapods
What is a Framework?
Encapsulates shared resources, such as a dynamic shared library, nib files, image files, localized strings, header files, and reference documentation in a single package.
The framework is a highly reusable component for your apps.
Frameworks have three major purposes:
Code encapsulation
Code modularity
Code reuse
The best reason to use frameworks is that they can be built once and be reused an infinite number of times.
- Umbrella framework (Only MacOS not support iOS, tvOS, WatchOS etc ): A framework that contains other frameworks, called umbrella framework.
Disadvantage:
Because of the sub-framework, its is create a duplicate framework inside a single application bundle. Which means the application size is larger. - Universal Framework (Fat framework): Using Lipo command, We create the universal framework. It’s not supported in Xcode 11.4.1 onward.
XCFramework[About] was introduced by Xcode 11 and it is a bundle that includes multiple architectures(arm, x86_64…) and platforms(iOS, macOS…). It replaces Universal Framework.
Library: In development, library means a collection of resources and code, compiled into one or more architecture.
- Static Library
- Dynamic Library
Static library — (.a) a unit of code linked at compile-time, which does not change.
However, iOS static libraries are not allowed to contain images/assets (only code). You can get around this challenge by using a media bundle though.
The disadvantage is a big output file
Dynamic library — (.dylib) a unit of code and/or assets linked at runtime that may change.
However, only Apple is allowed to create dynamic libraries for iOS. You’re not allowed to create these.
The disadvantage is a slow launch time since all dynamic libraries should be copied and linked.
Using dynamic libraries instead of static libraries reduces the executable file size of an app.
Difference b/w Framework vs Static Library vs Xcframwork
Steps to create Xcframwork
Step 1: Select iOS and choose framework.
Step 2: Create swift file and the function.
Step 3: Open Terminal and go to the root directory of the framework folder. and You have to replace TestFramework with your framework project name.
a. Archive binary for iOS Devicesxcodebuild archive \
-scheme TestFramework \
-configuration Release \
-destination 'generic/platform=iOS' \
-archivePath './build/TestFramework.framework-iphoneos.xcarchive' \
SKIP_INSTALL=NO \
BUILD_LIBRARIES_FOR_DISTRIBUTION=YESb. Archive binary for iOS Simulatorxcodebuild archive \
-scheme TestFramework \
-configuration Release \
-destination 'generic/platform=iOS Simulator' \
-archivePath './build/TestFramework.framework-iphonesimulator.xcarchive' \
SKIP_INSTALL=NO \
BUILD_LIBRARIES_FOR_DISTRIBUTION=YES
Step 4: Combine archive binary to xcframework with command.
xcodebuild -create-xcframework \
-framework './build/TestFramework.framework-iphonesimulator.xcarchive/Products/Library/Frameworks/TestFramework.framework' \
-framework './build/TestFramework.framework-iphoneos.xcarchive/Products/Library/Frameworks/TestFramework.framework' \
-output './build/TestFramework.xcframework'
Step 5: Use .xcframework in the vender app
Convert XCFramework to POD Dependency
Step 1: Push source code to git.Step 2: Create podspec. cd ~/Documents/Libraries/project - “Project Directory”pod spec create “podspec filename”open -a Xcode podspecName.podspec //open podspec fileStep 3: Podspec is look like following you should fill your requirements in podspec following is just an example: https://docs.google.com/document/d/1HDvvJAi5_ilct3fXoQw7iGKHVTb_rnv2lpp197tJYrs/edit?usp=sharingStep 4: Push Your podspec file to gitStep 5: Now you need to lint your project Open terminal to your project directory and try following command :-pod lib lint$ git tag '0.0.1'$ git push --tagsStep 6: Next Phase is for publishing your pods.replce with your email and username.pod trunk register nirajpaul.ios@gmail.com nirajpaul2You should quickly get an email from CocoaPods to verify your ‘session’. Verify your account by clicking the link provided in the email.All that is left is to push your podspec using Trunk to CocoaPods:Use following command using terminal -pod trunk push FantasticView.podspecNow our pod is successfully uploaded.