Tutorial on how to import KMA measurement Objective-C library into Swift project
Tutorial on how to import KMA measurement Objective-C library into Swift project
In this tutorial, you will find how to import KMA measurement Objective-C library into your Swift project.
The sample will be given with KMA tagging library, the steaming library will be very similar, please adapt the changes on your own project.
- Import the library into your project as before:
- If you want to import the Objective-C static library into your project, you will need a Bridging-Header file. In your project, create a new file, header file, the content will be like this:
you will need <Foundation/Foundation.h> and import "KMA_Spring.h" or "KMA_SpringStreams" - After import the library in, you will have to link the bridging file as the Objective-C Bridging header in your project,
the setting is in 'Build Settings', search for "Objective-C Bridging Header", and drag the bridging header file in. The first 3 steps will allow you the access to the library, the rest will be the implementation in your code just like before:
var springsensor: KMA_Spring? func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool { springsensor = KMA_Spring(siteAndApplication: "test",application: "testapp"); springsensor?.debug = true; springsensor?.ssl = true; let map: NSDictionary = ["stream":"testApp", SPRING_VAR_ACTION:SPRING_APP_STARTED] springsensor?.commit(map as [NSObject : AnyObject]) // Override point for customization after application launch. return true }
All the resources can be downloaded here:
For tagging: Swift_Bridging_Header.h
For Streaming: Swift_Bridging_Header_Streaming.h