title: Incompatible block pointer types - iOS
body: <p>I have an iOS app with a function which is in charge of making an asynchronous network request. The request itself works just fine, but the problem I am having is with the function <code>return</code> statement which is causing errors.</p>
  
  <p>Here is my function:</p>
  
  <pre><code>-(NSArray *)get_data:(NSString *)size {
  
      // Set up the data request.
      NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"http://mywebsite.com/info.json"]];
      NSURLRequest *url_request = [NSURLRequest requestWithURL:url];
      NSOperationQueue *queue = [[NSOperationQueue alloc] init];
  
      // Begin the asynchronous data loading.
      [NSURLConnection sendAsynchronousRequest:url_request queue:queue completionHandler:^(NSURLResponse *response, NSData *data, NSError *error) {
  
          if (error == nil) {
  
              // Convert the response JSON data to a dictionary object.
              NSError *my_error = nil;
              NSDictionary *feed = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableLeaves error:&amp;my_error];
  
              if (feed != nil) {
  
                  // Store the returned data in the data array.
                  NSArray *topping_data;
  
                  for (int loop = 0; loop &lt; [[feed objectForKey:@"toppings_data"] count]; loop++) {
  
                      NSString *size_name = [NSString stringWithFormat:@"%@", [[[feed objectForKey:@"toppings_data"] objectAtIndex:loop] valueForKey:@"Size"]];
  
                      if ([size_name isEqualToString:size]) {
                          topping_data = [[feed objectForKey:@"toppings_data"] objectAtIndex:loop];
                      }
                  }
  
                  return topping_data;
              }
  
              else {
                  return @[@"no data"];
              }
          }
  
          else {
              return @[@"no data"];
          }
      }];
  }
  </code></pre>
  
  <p>I am getting the following error message on the line of code <code>[NSURLConnection sendAsync....</code>:</p>
  
  <blockquote>
    <p>Incompatible block pointer types sending 'NSArray *(^)(NSURLResponse
    *__strong, NSData *__strong, NSError *__strong)' to parameter of type 'void (^ _Nonnull)(NSURLResponse * _Nullable __strong, NSData *
    _Nullable __strong, NSError * _Nullable __strong)'</p>
  </blockquote>
  
  <p>What am I doing wrong here?</p>
  
  <p>All I am trying to avoid, is the function returning BEFORE the asynchronous request has completed. Otherwise the function will not return any data, which is not what I want.</p>
  
  <p>Thanks for your time, Dan.</p>