Can one invoke Swift code in a Objective-C++ (.mm) file? Are there any simple workarounds if not?
I have a Xcode project that is a mix of Swift, Objective-C and C++. I have no problem going from Objective-C to Swift with the -Bridging-Header.h
or from Swift to Objective-C with the -Swift.h
.
I do however have a .mm file which is Objective-C++. When I try to #import "[ProductName]-Swift.h"
it throws many compile errors in the -Swift.h
file such as:
Cannot find protocol declaration for 'NSApplicationDelegate', did you mean 'NSConnectionDelegate'?
No type protocol named 'NSTableViewDataSource'
etc...
I have looked into several other similar questions such as Can I mix Swift with C++? Like the Objective - C .mm files but it does not seem to give me an explicit answer or a solution.
As I see it, my current workaround is to create a wrapper object in Objective-C that uses the Swift code and then import that into the Objective-C++ code.