As you probably already know, Apple recently announced a new programming language called Swift, a new and fresh look at programming for the Mac.
The main and obvious purpose of Swift is to replace Objective-C in the future.
To develop for the Mac, RemObject Software offers two products, DataAbstract for Cocoa and RemObject SDK for Cocoa.
These products are designed using native Apple technologies and are written in Objective-C.
They are available as frameworks and as static libraries.
This brings us to the important question: Can I use existing libraries written in Objective-C in a program written in Swift?
The answer to that question is yes.
In order to access classes from Objective-C libraries from Swift, you need to create a so-called Bridging Header File and name it according to your product module name followed by -Bridging-Header.h.
Then you need to edit this file to expose your Objective-C code to your Swift code.
Just import every *Objective-C * header you want to expose to Swift. In our case, this will be the root Data Abstract header:
|//// DAWithSwift-Bridging-Header.h// #import |
Also, do not forget to set the other build options to allow your application to locate and link it with the RemObjects libraries:
Library Search Path = "/Developer/RemObjects Software/Bin/$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME)" Other Linker Flags = -ObjC -all_load -lxml2 -lDataAbstract
And that’s it, now all public Objective-C headers listed in this bridging header file will be visible to Swift.
The Objective-C functionality will be available in any Swift file within that project automatically, without any import statements.
You can now use DA/RO classes with the same Swift syntax that you can use with system classes.
|//SWIFT // Set up rda and server accessvar dataAdapter: DARemoteDataAdapter let url: NSURL = NSURL(string:"http://localhost:7099/bin")self.dataAdapter= DARemoteDataAdapter(targetURL:url) dataAdapter.dataService.serviceName= "DataService" println("dataAdapter: \(dataAdapter.dataService.channel.targetURL)")|
Thanks for reading!