Create Framework in iOS 8

Kundan Kumar
3 min readApr 30, 2021

--

Creating a framework seems to be a tricky job in earlier version of iOS. I got an opportunity to work for framework creation and got some issues that takes a lot of time to resolve. So, i thought of writing a tutorial about how to create a framework.

In iOS 8 framework creation seems to be quiet easy.

Lets start open your Xcode → New Project → In left panel(select Framework & library under iOS section) → Select Cocoa Touch Framework → Click Next (Check Below Image)

Then give a Product Name and click on Next. (Check Below Image)

Click on next and then click on create. Now your framework file has been created.

Next now lets add some file. New file → select (iOS and then source in left panel) and then select Cocoa Touch class → Click Next → Give a class name and subclass of NSObject(select from dropdown) → Click Next. (check below image).

Now click create. You can see an NSObject class got created. I am going to teach you to just print(NSLog) using framework. If you want other things that your framework will do. You can code for it.

Go to Your NSObject class .h file and add “-(void)printLog;” Below @interface.

Now go to .m file and put this code below @implementation.

-(void)printLog

{

NSLog(@”This is a Framework creation test”);

}

We have added this log statement such that whenever this framework got added to other project and printLog method got called, This will log “This is a Framework creation test” .

Now Some settings.

Click on ProjectName → Click on build settings → Set “NO” to “Build Active Architecture only”.

Now go to Build Phases.

Click on Headers → You can see 3 sections (Public,Private and Project).There will be one .h file in Project, Drag and drop that .h file into public Section. This will make your framework file public and accessible from another class.

Now build your project. you can see that the red color framework in product folder of your project will turn black.

Now go there and click to show in finder (See below image).

There is your current created framework. Thats much you have to do to create the framework. Now drag and drop that framework to your project and use it.

Lets create a new project. Now drag and drop your framework there. Now in viewcontroller.m, import the framework header like this “#import <FrameworkTutorial/FrameworkTutorial.h>” and

also import the NSObject class included in framework like this “#import <FrameworkTutorial/FrameworkFunction.h>”. Now go to viewdidload and create an instance of your NSObject class and call the framework method like this

FrameworkFunction *frameWork = [[FrameworkFunction alloc]init];

[frameWork printLog];

Now you can see that its printing the value and basically your framework is working. :)

So, i think now you guys/gals understand how to create a framework in iOS. But have to add few things here. If you build your framework for device it will run only on device and if you build your framework for simulator it will run only in simulator. So, the question is to make it Universal. If the framework is universal it will work with both. Today, i have some busy schedule..So, whenever i will get time i will update the tutorial to make it universal..only 3–4 steps more. Till then Enjoy. :)

--

--

Kundan Kumar
Kundan Kumar

Written by Kundan Kumar

0 Followers

iOS Developer, Learner

No responses yet