繁体   English   中英

如何快速调用目标C中具有处理程序块的函数

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

请任何人告诉我如何从swift调用目标c类中定义的“ attemptLogin”登录函数

#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

,即时通讯就像

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


        }

data以NSObject形式返回,但应为NSDictionary

假设您在目标C中有屏蔽-

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

下面的代码将是您从swift调用时的代码-

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM