title: AFNetworking Return value from async task iOS
body: <p>I recently have asked about nil value from AFNetwirking GET query. <a href="https://stackoverflow.com/questions/20067190/always-got-nil-value-from-the-function-in-ios">Here is the question</a></p>
  
  <p>I've got an answer </p>
  
  <pre><code>+ (void)getRequestFromUrl:(NSString *)requestUrl withCompletion:((void (^)(NSString *result))completion 
  {
      NSString * completeRequestUrl = [NSString stringWithFormat:@"%@%@", BASE_URL, requestUrl];
      AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
      [manager GET:completeRequestUrl parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
          NSString *results = [NSString stringWithFormat:@"%@", responseObject];
          if (completion)
              completion(results);
      } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
          NSString *results = [NSString stringWithFormat:@"Error"];
          if (completion)
              completion(results);
      }];
  }
  
  [YourClass getRequestFromUrl:@"http://www.example.com" withCompletion:^(NSString *results){
      NSLog(@"Results: %@", results);
  }
  </code></pre>
  
  <p>Now I have another question: in MyClass I've got a method called getAllPlaces. </p>
  
  <pre><code>+ (void) getAllPlaces {
      NSString * placesUrl = [NSString stringWithFormat: @"/url"];
      NSMutableArray *places = [[NSMutableArray alloc] init];
      [RestfulActions getRequestFromUrl:cafesUrl withCompletion:^(id placesInJSONFormat) {
          NSArray *results = placesInJSONFormat;
          for (NSDictionary *tempPlaceDictionary in results) {
              Place *place = [[Place alloc] init];
              for (NSString *key in tempPlaceDictionary) {
                  if ([place respondsToSelector:NSSelectorFromString(key)]) {
                      [place setValue:[tempPlaceDictionary valueForKey:key] forKey:key];
                  }
              }
              [places addObject:place];
          }
  
  }];
  </code></pre>
  
  <p>It works, but I want to return non-void value (NSArray places). And now it raises question about async tasks again. What should I do? 
  I want to access from another class with <code>NSArray *places = [MyClass getAllPlaces]</code>
  I hope to get a correct answer. Thx, Artem.  </p>