Integrating with a Swift project

Ostetso has a native Objective-C interface but that doesn’t mean that you can’t still easily integrate it into a project that is written with Swift.

All of the main SDK documentation still applies but you will need to perform a few additional steps. Here’s how to do it...

  1. After you have dragged the Ostetso framework and bundle files into your Xcode project you will need to create an Objective-C bridging header file to allow your Swift code to access the Ostetso API. To do this, simply add a new header file to your project...in Xcode: File > New > File > (iOS or OS X) > Source > Header File. Name the new file OstetsoBridge.h.
  2. Edit OstetsoBridge.h and add the following lines:
    #import <UIKit/UIKit.h>
    #import "Ostetso/Ostetso.h"
  3. Go to your project build settings and find the setting called Objective-C Bridging Header. Add a value for that setting and include the path relative to your new OstetsoBridge.h file. For example, if you placed the new header is a subdirectory called Ostetso, you will enter “Ostetso/OstetsoBridge.h” here.
  4. While you are editing the project settings, don’t forget to add the -ObjC setting to the Other Linker Flags setting. Yes, this is also mentioned in the main SDK documentation but we just want to make sure that you don’t overlook this one.
  5. That’s basically all of the extra stuff that you have to do. Of course, all calls to Ostetso APIs must be done using Swift syntax. For example, your Ostetso initialization in your app delegate will look something like this:
    func application(application: UIApplication,
    didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
        Ostetso.setApplicationID("YOUR APP ID", appKey: "YOUR APP KEY",
                                 useProductionEnvironment: false, delegate: myDelegate)
        Ostetso.applicationDidFinishLaunchingWithOptions(launchOptions)
    
        return true
    }