2015-11-04 78 views
0

在此之前,我在C中工作。现在我需要用swift语言编写我的项目。同时使利用AFNetworking类Web服务调用我创建了一个名为FSAPI类中,我创建了以下2个街区类型'AnyObject'的值没有成员'loginUserWithUsername'

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; 
} 

请有人帮助我。提前致谢。

+1

请说明如何使用'sharedClient()'的定义。目前它的类型为AnyObject,这不是你想要的。 – Moritz

+0

已添加sharedClient()定义。 – Arti

回答

0

尝试本作中迅速块被视为封闭,

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 

     }) 
0

试试这个

将id替换为instancetype。

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

[FSAPI .sharedClient().loginUserWithUsername( “”,andPassword: “”,andGrant_type: “”,withCompletionBlock:空隙{ }>,andFailureBlock:requestFailureBlock(AFHTTPRequestOperation! NSError!) - > Void { })]]; 你能告诉我上面的代码行有什么问题吗? – Arti

相关问题