How to conform Swift class to C++ header

Hi People :)

I'm experimenting with Swift/C++ interoperability these days.

I'd like to understand how could I conform a Swift class to Cxx header:

Like this:

import Application

class App: Application {
    public func run() {
        let app = NSApplication.shared
        let delegate = AppDelegate()
        app.delegate = delegate
        app.run()
    }
}

But I got this error:

/Users/tonygo/oss/native-research/App.swift:27:7: error: inheritance from non-protocol, non-class type 'Application'
class App: Application {
      ^
ninja: build stopped: subcommand failed.

That seems normal indeed.

Reproductible example: https://github.com/tony-go/native-research/tree/conform-swift-to-cxx-header (Just run make)

I also have another branch on that repo where I use an intermediate Cxx bridge file that conforms to the :Application class and use the Swift API, like this: https://github.com/tony-go/native-research/tree/main/app

Bit I think that its a lot of boilerplate.

So I wonder which approach could I take for this?

Cheers :)

Add a Comment