0

I am trying to execute an asynchronous URL request:

    NSURLRequest* request=[NSURLRequest requestWithURL: [NSURL URLWithString: @"http://www.youtube.com/"]];
    NSOperation* operation=[NSOperation new];
    NSOperationQueue* queue=[NSOperationQueue new];
    [operation setCompletionBlock: ^()
     {
     }];
    [queue addOperation: operation];
    [NSURLConnection sendAsynchronousRequest: request queue: queue completionHandler: ^(NSURLResponse* response, NSData* data, NSError* error)
    {
        NSLog(@"%@",[data bytes]);
    }];

So I just need the data contained in the URL.But after few seconds (probably in the time that the newly created thread loads the data) the application crashes:

thread 6 : EXC_BAD_ACCESS (code=13, address=0x0)

The exact point is objc_msgSend_vtable5, in the NSLog line, when I try to print data bytes. PS: I'm using ARC.

Ramy Al Zuhouri
  • 21,580
  • 26
  • 105
  • 187

1 Answers1

3

The problem is that the method -[NSData bytes] has return type void * (and is a pointer to a raw byte buffer), but you're treating the return value as an object by trying to log it using the %@ format specifier. To fix this, just print just print data rather than [data bytes]; replace your line

NSLog(@"%@", [data bytes]);

with

NSLog(@"%@", data);
Nate Chandler
  • 4,533
  • 1
  • 23
  • 32