I’m attempting to retrieve a JSON file from an API for parsing. I’m using an NSURLConnection to get the data. It’s delegate receives the response and confirms that the MIME type is application/json. However, when the delegate calls this method:
-(void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
{
NSLog(@"Received route data");
[self.receivedData appendData:data];
NSLog(@"Data length: %d", data.length);
NSLog(@"Data length in property: %d", self.receivedData.length);
}
It logs the length of data as some integer. However, it logs the length of receivedData as 0. This is obviously wrong if there is data being appended to it.
receivedData is of the type NSMutableData and I use self.receivedData = [[NSMutableData alloc] init] when the object containing it is initialized. Is there a mistake I have made in appending the data?
Apparently, I had forgotten to set
self.receivedDatatostrong. As such, it was being released whenever the method that initialized it went out of scope and causing it to returnnilelsewhere.