问题
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.
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 *'
here is my code:
-(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];
}];
}
回答1:
First u can see the class type of the responseObject by typing NSLog(@"ClassType-%@",[responseObject class]).Then by custom delegate pass the responseObject to the desired type.
回答2:
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;
来源:https://stackoverflow.com/questions/28340840/conflict-in-return-type-of-the-function-ios