函数+ IOS的返回类型冲突 [英] conflict in return type of the function + IOS
问题描述
我正在构建一个iOS应用,并且正在使用AFNetworking库将数据发布到服务器.
I'm building an iOS app and i'm using AFNetworking library to POST data to the server.
我创建了一个函数来发布数据,并在应用程序的不同类中调用此函数.
I have created a function to post data and calling this function in different classes in my app.
我在名为"responseObject"的变量中获得请求的响应,并且我想在return语句中返回它,我无法识别responseObject的返回类型,因此无法确定该函数的返回类型,我尝试使用NSDictionary但得到以下警告:
I am getting response of the request in the variable called "responseObject" , And i want to return this in the return statement i am not able to identify the return type of responseObject and hence of the function,I tried using NSDictionary but getting following warning:
Conflicting return type in implementation of 'postData:parameters:': 'void' vs 'NSDictionary *'
这是我的代码:
-(void)postData:(NSString*)postUrl parameters:(NSDictionary *)params{
NSURL *baseURL = [NSURL URLWithString:@"http://xyz:2424/api/"];
AFHTTPSessionManager *manager = [[AFHTTPSessionManager alloc] initWithBaseURL:baseURL];
manager.requestSerializer = [AFJSONRequestSerializer serializer]; manager.responseSerializer = [AFJSONResponseSerializer serializer];
[manager POST:postUrl parameters:params success:^(NSURLSessionDataTask *task, id responseObject)
{
NSLog(@"response %@",responseObject);
}
failure:^(NSURLSessionDataTask *task, NSError *error) {
NSLog(@"\n============== ERROR ====\n%@",error);
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Error adding book" message:[error localizedDescription] delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil]; [alertView show];
}];
}
推荐答案
这意味着您的postData方法期望返回NSDictionary,但是您的方法说"void"-请查看头文件中的方法定义,我希望是这样:
This means your postData method is expecting an NSDictionary to be returned, however your method says "void" - have a look at the method definition in your header file , I expect it is:
-(NSDictionary*)postData:(NSString*)postUrl parameters:(NSDictionary *)params;
这篇关于函数+ IOS的返回类型冲突的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!