I have some Objective-C++ code like this:
// header
@interface MyObjcClass
- (void) myMethod: (NSString *) text;
I'd try
func mySwiftFunc(text: String) {
myObjcClassInstance.perform(#selector(NSSelectorFromString("myMethod:"), with: text as NSString)
}
If that won't work try:
func mySwiftFunc(text: String) {
let selector : Selector = NSSelectorFromString("myMethod:")
let methodIMP : IMP! = myObjcClassInstance.method(for: selector)
unsafeBitCast(methodIMP,to:(@convention(c)(Any?,Selector,NSString)->Void).self)(myObjcClassInstance,selector,text as NSString)
}
Probably possible without selector name "myMethod:"
String dependence, but I skipped the casting gymnastics as it's not the essence of the problem.