A Small Opening
In this article we will first go through how to integrate your Objective-C code into your new Swift code, and then go on to explain the interoperability between Swift and Objective-C and to close it all we will talk about CocoaPods. That will help you to connect existing Objective-C (Cocoa) code and libraries to new Swift projects for iOS 7 and iOS 8 apps that will run on the iPhone 6 and other iOS devices.
Objective-C integration with Swift
In the last WWDC among other stuff Apple announced their soon to be programming language Swift. After all the excitement that we all went through once we read/heard about the capabilities of Swift and after rushing and downloading Xcode 6 and iOS 8 to our computers and devices, we felt like our code is sad, alone and missing our good old libraries that we always counted on. So how do we actually use our good old libraries in our new Swift projects? For the next example we’ll create a sample app called “Colors”. The app will have one screen with six buttons whose names will be a color and its negative, for example : “black on white”, ”green on pink” etc. Once a certain button is clicked, the color and its negative will be applied to the color of the button and the view. Here comes the Objective-C code, the colors will be initiated through an Objective-C code that will take a string of a hex color and return a UIColor. Let’s begin!
We create a simple view application project: