Search code examples
iosobjective-cxcodeparse-platformswift

Connect Objective-C framework to Swift iOS 8 app (Parse framework)


I am trying to use an Objective-C framework with the Swift programming language for iOS 8 development. This is a specific case of an import but the general problem is:

How do you import an Objective-C framework into swift and get the import recognized?

I am trying to integrate the Parse framework into a swift application using the iOS 8 and Xcode 6 betas.

Here is the technique for Parse framework integration in Objective-C:

https://www.parse.com/apps/quickstart#social/mobile/ios/native/existing

I have downloaded the Parse framework as a compressed archive, extracted it, and imported it into Xcode 6 without any problems. Within my application it appears as a properly formatted framework under the name Parse.framework.

My current thought process is to modify the AppDelegate.swift file in the root directory of my project. Here is the current file without modifications (automatically generated by Xcode upon swift project creation):

https://gist.github.com/fconcklin/e8ef7d8b056105a04161

I have tried to import parse by adding the line import Parse below the line import UIKit. However, Xcode issues a warning that there is no such module found and the build fails.

I also tried creating a file ${PROJ_NAME_HERE}-Bridging-Header.h that contains the Objective-C import of Parse using import <Parse/Parse.h>. This line doesn't throw an error but appears to ultimately make no difference.


Solution

  • A "Fool Proof" way of adding a bridging header is as follows:

    If you have a Swift project, add a new Objective-C File to your project and Xcode will prompt if you want to configure your project with a bridging header. Press yes.

    If you have a Objective-C project, add a new Swift File to it and you will get the same prompt. Press yes.

    After you get the bridging header, you can delete the file you just added if you want to.