在此之前,我在目标C中工作。现在,我需要用快速的语言编写项目代码。在使用AFNetworking类进行Web服务调用时,我创建了一个名为FSAPI的类,在其中创建了以下2个块

typedef void (^requestCompletionBlock) (AFHTTPRequestOperation *operation, id responseObject);
typedef void (^requestFailureBlock) (AFHTTPRequestOperation *operation, NSError *error);


和以下登录方法

//****************** Login Service **********************//
- (void)loginUserWithUsername:(NSString *)username
             andPassword:(NSString *)password
             andGrant_type:(NSString *)grantType
     withCompletionBlock:(requestCompletionBlock)completionBlock
         andFailureBlock:(requestFailureBlock)failureBlock;


现在我不知道该如何打电话。我已经创建了桥接头文件并将FSAPI.h导入其中。

    FSAPI.sharedClient().loginUserWithUsername("", andPassword: "", andGrant_type: "", withCompletionBlock: requestCompletionBlock() {
     AFHTTPRequestOperation, id in

        //to do

        }, andFailureBlock: requestFailureBlock () {

        })

+ (id)sharedClient {
    static FSAPI *sharedClient = nil;
    static dispatch_once_t oncePredicate;
    dispatch_once(&oncePredicate, ^{
        sharedClient = [[self alloc] initWithBaseURL:[NSURL     URLWithString:baseServerURL]];
    });
    return sharedClient;
}


请有人帮我。提前致谢。

最佳答案

试试吧,因为swift中的块被视为关闭,

FSAPI.sharedClient().loginUserWithUsername("", andPassword: "", andGrant_type: "", withCompletionBlock: { (operation, response) -> Void in {

    //to do in success case

    }, andFailureBlock: { (operation, error) -> Void in {

        //to do in error case

        })

10-06 00:05