Colin Colin - 4 months ago 10x
iOS Question

Make A Call In Objective-C To A Method Using Swift String

I have a class method in Swift:

import Foundation

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

I'm then trying to call that function from Objective-C, but I'm borking something. Here's what I'm trying:

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

...but I'm getting the error:

"No known class method for selector 'registerDevice::deviceId:pushServiceToken:'"

What's the right way to make this call?

EDIT: Avi had the right answer. It turns out the method ended up being renamed to "registerDeviceWithUserId" in the ...-Swift.h file.

Avi Avi

You can find out how Xcode translates the Swift signature to Objective-C by checking the auto-generated <module>-Swift.h file. <module> will be the name of the app, if you haven't defined a module (and/or you're not building a framework).

To find the file (it doesn't appear in your project sources), hit cmd-shift-O and enter -Swift.h.