Within the iOS development world arguably there is a trend to adopt Apple's Swift language over Objective-C for new application development. History has taught Oracle not to pick sides in such debates, being "client agnostic" is a common and frequent term thrown around internal to Oracle these days to ensure we embrace all development technologies.
Extending this discussion around Swift to Oracle Mobile Cloud Service (MCS), Oracle's contemporary MBaaS solution, a question we're getting asked frequently is does MCS support Swift? Currently MCS support an iOS Objective-C SDK, but what about Swift?
The thing about this question is it typically doesn't come from veteran iOS developers, but from people who are in the process of learning iOS programming for the first time, have read about the Swift trend and picked that as their iOS language to learn, but don't yet know enough about the interoperability between Objective-C code and Swift.
In promoting Swift but realizing there was a huge Objective-C code base out there for iOS apps, Apple included an interoperable set of features to allow Objective-C to call Swift code and vice versa. In order for Swift to make use of Objective-C libraries, you implement a "bridging header file" which lists the Objective-C libraries to import and then makes them available to Swift in its native syntax.
So returning to MCS, what exactly would you need to do to build an iOS application in Swift, using the Objective-C SDK provided by MCS?
First you create a Swift app in Xcode. Then you load the MCS iOS SDK into your Xcode project as shown in this video. Next you add the bridging header file following these steps:
The example bridging header file:
Once you're done this you've pretty much set to go to call the MCS SDK libraries in Swift. What can be a bit of challenge from there is mentally converting Objective-C code examples to Swift. Objective-C uses a C like notation with pointers and an abundance of square brackets, while Swift has a simpler syntax in my opinion to learn, but notably drops semicolons as line terminators which my typing brain just can't help adding after 20 years as a programmer!
To help you on your way, following is an Objective-C example for authenticating MCS mobile users via the iOS MCS SDK, then the equivalent in Swift using the same SDK but also with the bridging header file. Here's the Objective-C example:
The following is the equivalent in Swift using the iOS SDK:
Hopefully this gives you a little taste of Swift with Oracle Mobile Cloud Service.