Search code examples
iosswiftcordovacordova-plugins

How Compatible is Apache Cordova with Swift?


I am about to start developing an iOS app that embeds a Cordova WebView and I would like to know how compatibles it is with the Swift programming language?


Solution

  • The cordova-ios library is written in Objective-C, but you can create Swift plugins. One thing to note is you must make your main plugin class accessible to Objective-C. See the example here.

    @objc(HWPHello) class Hello : CDVPlugin {
        func greet(command: CDVInvokedUrlCommand) {
            var message = command.arguments[0] as String
    
            var pluginResult = CDVPluginResult(status: CDVCommandStatus_OK, messageAsString: "Hello \(message)")
            commandDelegate.sendPluginResult(pluginResult, callbackId:command.callbackId)
        }
    }