Sal Aldana
Sal Aldana

Reputation: 1235

Calling a function with a callback in objective-c from swift

As most people I'm in the process of converting an existing app over to swift, and there are some features that can't be directly converted so instead I had to copy a few Objective-C classes over and setup a Bridging Header. All of this is done and I can call the functions, but when I call them I can't figure out how to include the callback and get the values from the callback from this method. Below is what I got so far.

This is the typedef and method from the Objective-C file

typedef void (^DictionaryAndStatusRecievedCallBack)(BOOL status, NSDictionary *dictionary);
-(void)verifyLoginCredentialsWithLoginName:(NSString *)loginName Passphrase:(NSString *)passPhrase callback:(DictionaryAndStatusRecievedCallBack)callback;

And here's how I'm calling it in the swift file

var serviceManager : MobileServiceManager = MobileServiceManager()
typealias onCompleteBlock = (status:Bool?, values:NSDictionary?)->Void
serviceManager.verifyLoginCredentialsWithLoginName("username", passphrase: "password", callback: ??)

I can't seem to figure out what to put in the callback area, I was trying a type alias since I saw another article mention that but I still couldn't get that to work either.

Upvotes: 1

Views: 2435

Answers (1)

Ch0k0l8
Ch0k0l8

Reputation: 837

var serviceManager : MobileServiceManager = MobileServiceManager()
serviceManager.verifyLoginCredentialsWithLoginName("username", passphrase: "password", callback: { (status, values) in  
/* Your code*/ })

Upvotes: 4

Related Questions