![](/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.