![](/img/trans.png)
[英]call function in swift file from objective-c file with completion handler (closure) syntax
[英]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.