Creating IOS Framework And Access Components

Lokesh Deshmukh
Prog-Ramming Solutions
4 min readAug 20, 2022

So, I started creating one framework for my learning and got to know that CREATING Framework is easy but steps were not so clear to me from all the sources. So I thought of writing one..

Let’s go step by step.

Create new Framework

Now your sample framework is created. We will add one file to start this framework flow.

I created this file name InitTestFrameWork.swift. As you can see we created one function with public modifier and a class with public modifier. AND public init() constructor

Also don’t forget to uncheck “Mac Catalyst” from Deployment Info. For Framework.

NOW Build the framework by clicking Run button

NEXT Step is to create a main project and link this framework.

As you can see our project is created. Now we are ready to link our framework. For that first build your framework once and you will see bundled framework in derive data.

Look at below screenshots

You will see your framework in Debug-iphoneos/Release-iphoneos directory. You need to drag this in your Main Project

Click on copy Items if needed.

Now your framework is added to the project . But it is not yet linked to do that refer below Image.

Drag and drop framework from same derive data folder to “Link Binary With Libraries” for Main Project again. Even if it shows that it’s already linked.

Perfect!!

Now we can call our framework code in the Project.

As you can see we can we called our framework and printed “hello” from framework function.

Now whenever you change the code in framework. Build the application and then run the project to get the updated changes.

NOW our first challenge is completed. Let’s call a View Controller of framework from Main Project.

Creating a storyboard in framework and calling it from our print function.

Till now we created new StoryBoard file with name StoryBoard. A view controller with name ViewController1.swift .

Add a button and label also in your view controller to see some difference.
Like this:

Now in our Main project we will call this with it’s identifier and storyboard name.

Create a button in your main project and call this piece of code to initiate your framework view controller.

VOLLA!!

You are done here.

Note: If you are adding custom fonts to your framework you also need to make sure that all the fonts are available in derive data folder. To do so you need to load fonts in framework memory before using it in main project.

Look at this piece of code:

If you want to load your custom fonts in framework it will not be done directly. You need to load fonts when you first call your frame work.

For more info you can check this link also:
https://stackoverflow.com/questions/30507905/xcode-using-custom-fonts-inside-dynamic-framework

If you did scrolled to this bottom of the page then Congrats !!

--

--

Lokesh Deshmukh
Prog-Ramming Solutions

Android developer | Photographer | Web Deveoper| Freelancer