Ios 类型为'的值;任何对象';没有成员';loginUserWithUsername';
在此之前,我在objective C工作。现在我需要用swift语言编写我的项目。在使用AFNetworking类进行web服务调用时,我创建了一个名为FSAPI的类,在该类中我创建了以下两个块Ios 类型为'的值;任何对象';没有成员';loginUserWithUsername';,ios,objective-c,swift,xcode7,Ios,Objective C,Swift,Xcode7,在此之前,我在objective C工作。现在我需要用swift语言编写我的项目。在使用AFNetworking类进行web服务调用时,我创建了一个名为FSAPI的类,在该类中我创建了以下两个块 typedef void (^requestCompletionBlock) (AFHTTPRequestOperation *operation, id responseObject); typedef void (^requestFailureBlock) (AFHTTPRequestOperati
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;
}
请有人帮帮我。提前谢谢。试试这个
将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;
}
试试这个,因为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
})
请说明如何定义
sharedClient()
。当前它的类型为AnyObject,这不是您想要的。添加了sharedClient()定义。[FSAPI.sharedClient().loginUserWithUsername(“,and Password:”,Grant_type:”,withCompletionBlock:Void{}>,FailureBlock:requestFailureBlock(AFHTTPRequestOperation!,NSError!)->Void{})]; 你能告诉我上面这行代码有什么问题吗?