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

After further research I found the solution and realized that I was just confused.

The correct approach is as follows:

  • Import your Objective C framework by dragging and dropping the framework into an Xcode 6 Swift project.

  • Create a new Objective C file in your project (File->New->File [Objective C for iOS]).

  • Accept the prompt (agree) to create a bridging header file between Objective C and Swift.

  • Delete your newly created Objective C file but retain the bridging header file ${YOURPROJ}-Bridging-Header.h.

  • In the Bridging header file, import your framework using the standard Objective C import syntax (e.g. #import <Parse/Parse.h>).

  • This relinquishes the need to perform an import Parse statement in your AppDelegate.swift file. You can now write code that utilizes whatever framework as long as it is imported using the bridging header. It is available throughout your project’s Swift files.

Now, if you would like to test Parse integration in your project, you can type Parse. and use code completion to browse the framework and see that the code completion is indicative of a successful import.

However, there is another caveat here that needs to be addressed when using a Bridging Header file. All dependencies of the framework need to be specified in the Bridging Header file as well. In the case of integrating Parse framework into a Swift application your Bridging Header file will look like this:

 #import <Foundation/Foundation.h>

 // Parse Dependencies
 #import <AudioToolbox/AudioToolbox.h>
 #import <CFNetwork/CFNetwork.h>
 #import <CoreGraphics/CoreGraphics.h>
 #import <CoreLocation/CoreLocation.h>
 #import <MobileCoreServices/MobileCoreServices.h>
 #import <QuartzCore/QuartzCore.h>
 #import <Security/Security.h>
 #import <StoreKit/StoreKit.h>
 #import <SystemConfiguration/SystemConfiguration.h>

 // Import parse framework
 #import <Parse/Parse.h>

Hope this helps.

Leave a Comment