conflict in return type of the function + IOS

2019-09-04 08:04发布

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];


          }];

}

2条回答
聊天终结者
2楼-- · 2019-09-04 08:23

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;
查看更多
Anthone
3楼-- · 2019-09-04 08:41

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.

查看更多
登录 后发表回答