类型的价值' AnyObject'没有会员' loginUserWithUsername'

时间:2015-11-04 11:43:02

标签: ios objective-c swift xcode7

在此之前我在目标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;
} 

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

2 个答案:

答案 0 :(得分: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;
} 

答案 1 :(得分:0)

试试这个,因为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 

        })