I am using a third-party component that has two inits. This is taken from the header file:
class ExampleClass {
public:
ExampleClass();
void init();
void init(int num);
...
I am, inevitably, trying to use the variant with the int
parameter. Intuitively, I tried:
var example = ExampleClass()
example.init(3)
However, this fails with:
'init' is a member of the type; use assignment to initialize the value instead
error: cannot convert value of type 'int' to expected argument type 'ExampleClass'
Since the argument is assigned to a private
property, doing this also fails:
var example = ExampleClass()
example.intProp = 3
Even though it's third-party and I don't want to change it, I tried swapping the order of the inits, but it made no difference.
I found the documentation, here: https://www.swift.org/documentation/cxx-interop/#using-c-type-aliases that suggests using:
#include <swift/bridging>
void sendCopy(const std::string &) SWIFT_NAME(send(_:));
Re-writing for my own use:
void ExampleClass::init(int) SWIFT_NAME(initWithInt(_:));
This fails with:
`- error: expected expression
`- error: variable has incomplete type 'void'
The ticks point to the closing bracket of (int)
. I tried using .
instead of ::
and then removing the class specifier. All give the same error. I also looked at the automatic aliasing, but it didn't seem to apply in my case.
How do I access the overloaded version?