Objective C class 中的方法调用 Swift
Objective C class method call in Swift
j2objc在头文件中创建了一个class方法声明如下:
(void)startWithNSString:(NSString *)folderPath
withNSString:(NSString *)pushyToken
withInt:(jint)port
withInt:(jint)width
withInt:(jint)height
我正在尝试从 swift 代码调用它。
谁能告诉我怎么做。
编辑#1:
马特,我添加了如下标签:
let screenSize = UIScreen.main.bounds
let screenWidth:Int32 = Int32(screenSize.width)
let screenHeight:Int32 = Int32(screenSize.height)
let pushyToken = UserDefaults.standard.object(forKey: "pushyToken") as? String ?? String()
SocketClient.startWithNSString("", withNSString:pushyToken,
withInt:8000, withInt:screenWidth, withInt:screenHeight)
我遇到错误:
'startWithNSString(_:withNSString:withInt:withInt:withInt:)' has been
renamed to 'start(with:with:with:with:with:)'
这就是 Xcode 9 在自动完成中给我的内容:
object.abc(with: "Folder path", with: "Token", with: portNumber, with: width, with: height)
假设您在 Swift 中有名为 portNumber
、width
和 height
的适当类型的变量。 (都是整数吗?)
j2objc在头文件中创建了一个class方法声明如下:
(void)startWithNSString:(NSString *)folderPath
withNSString:(NSString *)pushyToken
withInt:(jint)port
withInt:(jint)width
withInt:(jint)height
我正在尝试从 swift 代码调用它。
谁能告诉我怎么做。
编辑#1:
马特,我添加了如下标签:
let screenSize = UIScreen.main.bounds
let screenWidth:Int32 = Int32(screenSize.width)
let screenHeight:Int32 = Int32(screenSize.height)
let pushyToken = UserDefaults.standard.object(forKey: "pushyToken") as? String ?? String()
SocketClient.startWithNSString("", withNSString:pushyToken,
withInt:8000, withInt:screenWidth, withInt:screenHeight)
我遇到错误:
'startWithNSString(_:withNSString:withInt:withInt:withInt:)' has been renamed to 'start(with:with:with:with:with:)'
这就是 Xcode 9 在自动完成中给我的内容:
object.abc(with: "Folder path", with: "Token", with: portNumber, with: width, with: height)
假设您在 Swift 中有名为 portNumber
、width
和 height
的适当类型的变量。 (都是整数吗?)