If you are an experienced iDeveloper, you’d have probably heard of a term called Frameworks, more specifically, the ‘Dynamically Linked Frameworks’. Now this is the most intimidating term for most of the folks out there but believe me, its insanely simple to build one. Bear with me. The only thing that you have to remember, is that Apple now allow developers to make dynamically linked Cocoa Touch Frameworks for iOS, to package up your code in a most efficient way. Thats it! (I’m not going into much of the details though, its a pretty deep topic)

Well, I was developing a nice and clean wrapper around the CoreMotion Framework, called the MotionKit, which allows you to retrieve the raw data from the Accelerometer, Gyroscope and Magnetometer in just a few lines of code. I kept it completely open sourced from the day first, and soon I started receiving hunderds of emails from many of the fellow Developers out there, asking for the licensing scheme of MotionKit, so that they could leverage the power of sensors into their apps while making them more engaging and enhancing the overall user experience. I didn’t know this wrapper will gain so much of traction, so I decided to distribute it through CocoaPods and Carthage but wait a minute! Carthage only supports Dynamic Frameworks and CocoaPods hate swift (at the time I’m writing this article). So, the only choice left, was to make a Cocoa Touch Framework, and distribute it through Pods and Carthage.

It was very intimidating when I thought about the distribution of MotionKit through CocoaPods and Carthage, because of the fact that it was purely written in Swift. But, it came out that it was really easy to do so, at least for me. Lets have a look.

A simple Swift file

Its very obvious that you need to have some kind of functionality built right into the Framework that you wanna build. So I’ll start with just a simple Swift file that I made. A very simple one.

class SwiftFrameworks {

init (){

println("Class has been initialised")

}



fun doSomething(){

println("Yeah, it works")

}

}

Long story short, to make it work seamlessly with your Framework, you have to make every method and class initialisers public. Simple enough. The above swift file would then look something like this.

public class SwiftFrameworks {

public init (){

println("Class has been initialised")

}



public fun doSomething(){

println("Yeah, it works")

}

}

Lets name that file, ‘MotionKit.swift’ (Please don’t mind my naming conventions, I’m made that way).

Now head over to the Xcode, and create a new CocoaTouch Framework. I’ll name it MotionKit. Just launch the Xcode ► Start New Project ► Under the iOS, select Framework & Library ► Select Cocoa Touch Framework ► Name it and Press Enter.