Swift Framework — Ch: 1 . Develop a Swift Framework

Swift Frameworks are Just Awesome!

Find this chapter in Spanish by Daniel Isaac.

WORE — Write Once Run Everywhere, Is now used for Swift along with Java.

Image for post
Image for post

Indeed Swift became a popular programming language and evolving day-by-day.

Developing a Swift Framework has it’s own Advantages as follows.

  1. Hide your code implementation.
  2. As .framework files are already compiled, it will reduce recompilation and save your time while developing.
  3. It is what Apple uses, Ex: UIKit.framework.

So what are you looking for?, let’s start developing your own Swift framework now.

Tools used : XCode 9.3+, Swift 4.1+

Step 1:- Setup Framework Project

  • Create new XCode project.
Image for post
Image for post
  • Click on Cocoa Touch Framework
Image for post
Image for post
Choose Cocoa Touch Framework
  • Name your project, we have used AlamoWater sounds similar to Alamofire. (Make sure to choose language — Swift)
Image for post
Image for post
  • Click AlamoWater folder inside your target and press ⌘ + N.
  • Choose File Name AlamoWater and Subclass of: NSObject
Image for post
Image for post

Step 2:- Write some Code

Add following code inside AlameWater.swift.

Note:- Make sure your class and methods are open.

AlamoWater.swift

Step 3:- To create framework for both iOS Device and Simulator add new Aggregate target to your project.

Image for post
Image for post
Image for post
Image for post
Add Aggregate target
Image for post
Image for post
Image for post
Image for post
Image for post
Image for post
Add Run Script
Run Script
  • Note:- In Run Script, Make sure to change AlamoWater with your project name.

Step 4:- Build your first framework by Choosing UniversalAlamoWater target pressing ⌘ + B

After build completed,You will see Finder opening with Your Framework in that.

Happy Happy :)

Step 5:- Add this framework to your any project and use it.

ViewController.swift

Note:- If you are getting following error,

… Reason: image not found

Make sure your framework is added in both Embedded Binaries and Linked Frameworks and Libraries

Get Full SourceCode on Ch: 1 — GitHub.


Captain — iOS Experts

We help you develop (really) awesome apps.

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store