Making Your own Framework in iOS

Posted By : Aditya Kumar Sharma | 23-Apr-2018

We commonly use our some methods in every application. For each application, we need to create it from starting or we do is a create a swift file and Copy and Paste it from the old projects. So for this purpose, we would be making our very own framework. By this, we just need to import that framework in starting the project and start using them.

 

We are making a framework for converting the timestamp to local date/time or vice-a-versa.  So let’s built this framework:

 

Create a Cocoa Touch Framework

 

Open Xcode > File > Project. Scroll to Framework & Library and choose Cocoa Touch Framework and go for Next.

 

Give your framework a name and click Next and create the project.

 

 

Remember to Enable the Bitcode to Yes.

By going to Target > Project Name > Build Setting.

 

 

Now create a swift file and put your required methods there. Remember, to make func or the class public. So that it can be accessed from other files.

 

 

 

Now you can use this framework in your own projects by adding the framework.

 

Open Products folder and select .framework file and find its location in the Finder.

 

 

 

Just copy this framework and save it somewhere you want.

 

Now open your main project and Select Project, choose Target > Project name > Select general and scroll to Embedded Binaries and click “+”  to add the Framework. Click On Add other and navigate to that directory and select the framework created.

 

Please remember to check the box “Copy items if needed”.

 

Now you can use the framework just by importing the framework in our .swift files.

 

Thanks

 

About Author

Author Image
Aditya Kumar Sharma

Aditya is a bright iOS developer, have knowledge of objective C, swift, swift 3, JSON, Core data and iPhone development. Apart from that he loves to travel and explore new things.

Request for Proposal

Name is required

Comment is required

Sending message..