conflict in return type of the function + IOS

你说的曾经没有我的故事 提交于 2019-12-13 03:04:14

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!