How to Call a function having handler block in objective C from swift

748 views Asked by At

Please can anybody tell me how to call "attemptLogin" login function defined in objective c class from swift

#import <Foundation/Foundation.h>

@interface LoginHandler : NSObject<NSURLConnectionDelegate,NSXMLParserDelegate>{

}

typedef void (^CustomCallback)(NSDictionary *responseObj);

-(void)attemptLogin:(NSString *)userName andPassword:(NSString *)password completionHandler:(CustomCallback) callback;
@end

, i m calling in swift file like

var loginHandler = LoginHandler();
        loginHandler.attemptLogin(userMob, andPassword: userPass){
            data in


        }

but data is returned in NSObject form, but it should be NSDictionary

1

There are 1 answers

0
Santu C On

Suppose you have block in Objective C -

 [[MyDataStore instance] askUserForMe:^(Person *person, NSError *error){
        // do things with myself that aren't strange
    }];

Below code will be when you call from swift -

MyDataStore.instance().askUserForMe() {
    person, error in 
    // do things with myself that aren't strange
}