šŸ“± Mobile

[Share] Swift. Static and Dynamic Libraries. Frameworks

date
Jan 15, 2024
slug
swift-static-and-dynamic-libraries-frameworks
author
status
Public
tags
#ios
summary
In this article, I tried to visualize the process of compiling, linking, and simply working with libraries and frameworks. I hope this work will be a good extension of materials you can find all over the Internet and in the Apple documentation
type
Post
thumbnail
category
šŸ“± Mobile
updatedAt
Feb 18, 2024 08:59 AM
notion image
notion image
notion image
Static libraries are fully embedded into the result executable binary
Ā 
notion image
Dynamic ones behave differently. The result executable binary has just references to the functions of that libraries. And the code of the functions is loaded at runtime
Ā 
notion image
notion image
Ā 
Letā€™s take a look at what Xcode and iPhone do under the hood:
notion image
notion image
Ā 
And now letā€™s see what frameworks are:
notion image
To summarize everything above, letā€™s say that inĀ iOS/macOS development, there are two types of modules:
  • library, and its synonyms like a static library, static framework
  • framework, and its synonyms like a dynamic framework
Telling aboutĀ librariesĀ or static frameworks, people assumeĀ staticĀ libraries ā€” modules, that are fully embedded into the result executable binary
And speaking aboutĀ frameworks, they refer toĀ dynamicĀ libraries that are wrapped by frameworks and linked to the executable binary via references to their functions
Ā 

Ā 
There are several helpful terminal commands that allow you to determine the type of binary and get some useful information:
notion image
notion image
notion image
notion image
notion image
notion image
notion image
Ā 
In our project, we use cocoapods as Swift dependency manager. As a bonus, letā€™s see how Xcode treats its dependencies and how they are transformed into static libraries or dynamic frameworks:
notion image
notion image
notion image
I hope it will help you to get closer to the Swift and iOS development and to have a better understanding of not so simple topic.
Ā 
Ā