我们试图在objective-c实现中引用swift方法.
Swift 3类:
import Foundation
@objc class MySwiftClass: NSObject {
override init() {
super.init()
}
func sayHello() -> Void {
print("hello");
}
func addX(x:Int, andY y:Int) -> Int {
return x+y
}
}
Run Code Online (Sandbox Code Playgroud)
Objective-C实现(Objective-cm):
#import "ProductModuleName-Swift.h"
MySwiftClass* getData = [[MySwiftClass alloc]init];
[getData sayHello] //works
[getData addX:5 addY:5] //No visible @interface for 'MySwiftClass' declares selector 'addX:addY'
Run Code Online (Sandbox Code Playgroud)