ios - 类型 'AnyObject' 的值没有成员 'loginUserWithUsername'

标签 ios objective-c swift xcode7

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

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 中的 block 被视为闭包,

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 

        })

关于ios - 类型 'AnyObject' 的值没有成员 'loginUserWithUsername',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33520979/

相关文章:

Swift Firebase 如何停止进程?

ios - 想要获取上个月时的 NSDateComponents 问题

ios - 如何设置默认设备以在 Ionic 中进行模拟?

ios - 在 Xcode 的另一个 ViewController 中打开 QR 链接

ios - ios 顶部带有标签栏的自定义 uitableview

ios - 在没有 iCloud 授权的情况下,有什么方法可以从 iCloud 商店读取数据?

objective-c - 在每次打开时修改 NSMenu 结构?

ios - 单击每个 tableview 单元格 iOS 时显示/隐藏 tableviewCells( Accordion UITableView)

iphone - 帮助着色由图像蒙版/边界定义的图层并将图像覆盖在顶部

ios - 在快速完成所有后台进程后执行功能