Book Image

Application Development with Swift

By : Hossam Ghareeb
Book Image

Application Development with Swift

By: Hossam Ghareeb

Overview of this book

Table of Contents (14 chapters)

Using Objective-C and Swift in a single project


As an iOS developer, before Apple released Swift, you may feel worried about your old code in Objective-C and wonder if you can use them together. The answer is yes, you can use Swift and Objective-C together in a single project, and everything will be fine, irrespective of whether the project was originally in Swift or Objective-C. This compatibility is very important in making the language easy to use and has been welcomed by all developers. So, you can use Objective-C frameworks (system frameworks or your custom frameworks) in Swift, and you can use Swift API's in Objective-C code.

Importing Objective-C in the Swift project

To import some of your old Objective-C files in the Swift project, you will need a bridging header file to expose these files to Swift. Xcode offers to create the bridging header file for you once you add a Swift file in an Objective-C project or vice versa. Check the following image, where Xcode asks you to create the...