Integrating Objective-C with Swift

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:
Creating a new Xcode project

weiterlesenIntegrating Objective-C with Swift

iOS 8 Document Provider extension

Extensions In General

So what are these new extensions that we all keep hearing about? In the last WWDC 2014, one of the more interesting subjects was the App Extensions, which is basically a new tool that allows different 3rd party apps to communicate with each other, or more correctly, allows them to have a controlled shared environment in order to increase the file accessibility between apps in iPhones, iPads and all the iOS system devices. Us developers can now create different extensions in our app to send, open or edit different kind of file like images, docs, pdf’s etc. A „shared folder“ for different uses and file sharing.

In The Past

Up until now, the only ways to transfer a file for example from one app to another was to find your file through a provider’s app and click the “Open in” option to send a copy of the file to another app, that can handle your file once it gets it.

weiterleseniOS 8 Document Provider extension