How to Build Your Own iOS Framework

Why use it while you can build it

Firda Sahidi
iOSnesia
3 min readFeb 23, 2020

--

Photo by Annie Sprat on Unsplash

When you finally can build an iOS app, that’s cool. However, if you using a lot of third-party frameworks, you will feel that your application will get so much long to compile. Moreover, when it comes to new Swift or new OS, but the framework you’re using not compatible with it, it could cause big trouble. When you build your own framework, you can change it wherever you need too, without waiting for third-party. It could also reduce your apps build time and apps size. So, here’s the step of how to build your own framework in less than 5 minutes.

Creating Cocoa Touch Framework

The first thing to do is to make Cocoa Touch Framework project. To do so, create new project in XCode, then choose Cocoa Touch Framework.

Object Attribute Class

There are two types of iOS Framework that I will explain in this article. The first one is object attribute class, the one I believe you ever use when using CocoaPods Libraries. This will look like this when it was implemented.

Yes, you can change the attributes of objects directly in the attributes inspector when using it. So, you don’t have to re-code the method of object that you want to have specific attributes. To implement this, just create a Cocoa Touch Class, and choose the subclass to the object you desire (for this article I will use UIView). Then use @IBInspectable to make options that exist in the attributes inspector. Use didSet to get value from attributes inspector and assign them to variable in the class. Set your function in awakeFromNib().

Function Class

Let’s say you want to have reusable function/method, and then you want to create framework about that. Just simply make Swift Class, put your function in there. For the example is simple function to print string like this.

Build the Framework

After you finish everything, just build it, and your framework is ready to use. It located under Products folder of your project, the one that has .framework extension. Right click and choose show in finder to get the framework.

Using your Framework

To using framework, just drag the framework to the Project’s embedded binaries. Checklist copy item is needed and choose Create Group. After finish, you can import the Framework in your Project class.

--

--

Firda Sahidi
iOSnesia

Indonesian iOS Developer with 6+ years of professional experiences. Recent MSc Fintech Graduate from University of Edinburgh. Check out my list below!