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 :)

Without making the assumption of the Application type the compiler is pretty much accurate in its message. https://www.swift.org/documentation/articles/wrapping-c-cpp-library-in-swift.html

Thanks I'll take a look :)

It seems that is not what I'm looking for. In a nutshell I'd like to find a way for a swift class to conform to a class definition from a C++ header file.

How to conform Swift class to C++ header
 
 
Q