title: How to return NSData from NSURLSessionDataTask completion handler
body: <p>I am trying to make a simple class that I can use to call a post web service.</p>
  
  <p>Everything is working perfectly except that I am not able to return the <code>NSData</code>.</p>
  
  <p>This is my code:</p>
  
  <pre><code>+ (NSData *)postCall:(NSDictionary *)parameters fromURL:(NSString *)url{
      NSURLSessionConfiguration *configuration = [NSURLSessionConfiguration defaultSessionConfiguration];
      NSURLSession *session = [NSURLSession sessionWithConfiguration:configuration];
      NSMutableArray *pairs = [[NSMutableArray alloc]init];
      for(NSString *key in parameters){
          [pairs addObject:[NSString stringWithFormat:@"%@=%@", key, parameters[key]]];
      }
      NSString *requestParameters = [pairs componentsJoinedByString:@"$"];
      NSURL *nsurl = [NSURL URLWithString:url];
      NSMutableURLRequest *urlRequest = [NSMutableURLRequest requestWithURL:nsurl];
      [urlRequest setHTTPMethod:@"POST"];
      [urlRequest setHTTPBody:[requestParameters dataUsingEncoding:NSUTF8StringEncoding]];
      NSURLSessionDataTask *dataTask = [session dataTaskWithRequest:urlRequest completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
          //return data;
      }];
      [dataTask resume];
  
      return nil;
  }
  </code></pre>
  
  <p>Please notice that I have <code>//return data</code> but it gives me this error </p>
  
  <pre><code> Incompatible block pointer types sending 'NSData *(^)(NSData *__strong, NSURLResponse *__strong, NSError *__strong)' to parameter of type 'void (^)(NSData *__strong, NSURLResponse *__strong, NSError *__strong)'
  </code></pre>
  
  <p>My question is:</p>
  
  <ol>
  <li><p>Is my way good or it will cause me problems in the future? I don't have image to download and I don't have anything to upload, I just have to send simple string data and receive simpe string data. Or it will be better to but that code in each function independently?</p></li>
  <li><p>How can I return the data please? </p></li>
  </ol>