用Objective-C调用一个使用Swift字符串的方法

时间:2016-06-23 19:19:30

标签: ios objective-c swift

我在Swift中有一个类方法:

import Foundation

public class MyClass : NSObject{
    class func registerDevice(userId uId: String, deviceId dId: String, pushServiceToken token: String) -> Void{ /*...*? }
}

然后我试图从Objective-C调用该函数,但我正在做些什么。这是我正在尝试的:

[MyClass registerDevice: @"user id" deviceId: [UIDevice currentDevice].identifierForVendor.UUIDString pushServiceToken: registrationToken];

...但我收到了错误:

  

“没有已知的选择器类方法'registerDevice :: deviceId:pushServiceToken:'”

拨打此电话的正确方法是什么?

1 个答案:

答案 0 :(得分:1)

通过检查自动生成的<module>-Swift.h文件,您可以了解Xcode如何将Swift签名转换为Objective-C。如果您尚未定义模块(和/或您没有构建框架),<module>将是应用程序的名称。

要查找文件(它没有出现在您的项目源中),请点击cmd-shift-O并输入 -Swift.h

编辑:在这种情况下,该方法被命名为“registerDeviceWithUserId”。

相关问题