簡體   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