📱 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.