title: converting NSData to UIImage - working with NSURLRequest
body: <p>I've been working with AFHTTPRequestOperationManager calling my service that return an image and my code looked like this:</p>
  
  <pre><code>NSString *baseURLString = @"http://get_image/";
  
  @try {
      AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
      [manager GET:baseURLString
        parameters:nil
           success:^(AFHTTPRequestOperation *operation, id responseObject) {
               NSString *imageStr = responseObject[0];
                if([imageStr isKindOfClass:[NSNull class]]==NO)
                {
                NSData *imageData = [NSData   dataWithBase64EncodedString:imageStr];
                UIImage *image = [UIImage imageWithData:imageData];
                self.myImage = (image==nil)? [UIImage imageNamed:@"noPhoto"]: image;
                }
           }
           failure:^(AFHTTPRequestOperation *operation, NSError *error) {
               self.myImage = [UIImage imageNamed:@"noPhoto"];
           }];
  }
  @catch (NSException *exception) {
      NSLog(@"exception %@", exception);
  }
  </code></pre>
  
  <p>since AFHTTPRequestOperationManager is async and I need a sync call how can I complete this code to produce my image:</p>
  
  <pre><code>NSString *baseURLString = @"http://get_image/";
  NSURLResponse *response;
  NSError *error;
  
  NSURLRequest *urlRequest = [NSURLRequest requestWithURL:[NSURL URLWithString:p_baseURLString] cachePolicy:NSURLRequestReturnCacheDataElseLoad timeoutInterval:30];
  
  // Make synchronous request
  NSData *imageRequest = [NSURLConnection sendSynchronousRequest:urlRequest returningResponse:&amp;response error:&amp;error];
  
  ???
  
  UIImage *image = [UIImage imageWithData:imageData];
  self.displayedApartment.exteriorImage = (image==nil)? [UIImage imageNamed:@"noPhoto"]: image;
  </code></pre>
  
  <p>This is what I've tried in place of ??? all resulted in image=nil</p>
  
  <ul>
  <li>using the imageRequest data as is</li>
  <li>converting the imageRequest to base64 with <code>[[NSData alloc] initWithBase64EncodedData:imageRequest options:0];</code></li>
  <li><p>converting it to string and back to NSData</p>
  
  <p><code>NSData NSString *imageStr = [NSString stringWithUTF8String:[imageRequest bytes]];
  NSData *imageData = [NSData   dataWithBase64EncodedString:imageStr];</code></p></li>
  </ul>