Introduction — How to create an iOS Framework Pt0

El Moez Amira
3 min readApr 26, 2022

--

Have you ever wondered what’s behind the frameworks you are importing to your apps? Or maybe you had thoughts about creating one? Did the idea of modularizing your code crossed your mind? if so, you probably clicked on the right link!

In this series, we will cover many topics such as the basics of how to generate a framework, modularization, documentation, packaging and distribution.

Lately I have been exploring the world of iOS frameworks, having read many articles, watched several tutorials and learned a lot from the amazing iOS community on different platforms, I decided to share my newly acquired skills with you, in the form of a short series of posts, so you can expect me to post updates about this subject on a weekly basis.

Today’s post will serve the purpose of an introduction, so let’s start by defining a framework.

A software framework is an abstraction in which software, providing generic functionality, can be selectively changed by additional user-written code, thus providing application-specific software. It provides a standard way to build and deploy applications and is a universal, reusable software environment that facilitates the development of software applications

So how can we translate that into the apple ecosystem ? Here’s a more suitable definition :

Frameworks are bundles that contain a linkable library (usually a dylib) and the associated resources and headers for development.

There are two types of binary frameworks :

  • Universal frameworks
  • XCFrameworks

Universal Frameworks :

A universal framework ( also called Fat framework ) is the combination of two different versions of .framework files :

  • Real devices version : armv7, armv7s, arm64
  • Simulator version : x86_64, i386

The reason we have to use two separate versions is due to the difference in architectures.

While Fat frameworks are a good solution for development purposes, they lack the ability to support multiple platforms such as iOS, Mac OS, WatchOS.

Starting in Xcode 12.3, Fat frameworks cannot be used anymore. This series will obviously focus on XCFrameworks.

XCFrameworks :

XCFrameworks are the new and official form of distributing binary frameworks in the Apple platforms, they were introduced to the world in 2019 to solve many ongoing inconveniences that developers were facing. They provide common roof for different OS variants of the framework and work perfectly with both physical devices and simulators. You can for example have a variant that uses UIKit for iOS interfaces and AppKit for MacOS interfaces.

In addition, XCFrameworks can also bundle up static libraries and their corresponding headers, and yes, XCFrameworks support binary distribution of Swift and C-based code!

XCFrameworks are also easily distributed using Apple’s first party dependency manger Swift Package Manager ( SPM ). I will cover this topic in details in a future post.

Before concluding, I’d like to share with you a great article that I enjoyed reading, It discusses the Whys and the Hows Apple introduced XCFrameworks.

Conclusion :

Before diving into technical posts, I felt like the right way to start this series is by clarifying and showing you the bigger picture first, hence I consider this post part zero of the series ( not part 1 ).

This marks the end of this post so make sure to click on the clap button 👏👏 if you liked it.

In the next post, we will start developing an XCFramework from scratch so follow me to stay up to date with this series, and of course, feedback is always appreciated.

Happy coding !

How To Create an iOS Framework

6 stories
SwiftUI Documentation viewed in Xcode 13

--

--

El Moez Amira

Software engineer / iOS developer  | Twitter : @elmoezamira from Tunisia 🇹🇳