This code is ill conceived:
[NSURLConnection connectionWithRequest:request delegate:self];
while(!self.finished) {
[[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode beforeDate:[NSDate distantFuture]];
}
NSArray *last_name = [[self.myDictionnaryData objectForKey:@"data"] valueForKey:@"lastname"];
Because once you start the connection you should not be waiting for the response is a loop. The response is asynchronous so you should use it when it becomes available in connectionDidFinishLoading:
. Move all of your handling code to there (or, better, to a method called from there).
Other issues:
You shouldn't be doing this:
_myDictionnaryData = [[NSMutableDictionary alloc] init];
(because you will never use that instance before it is replaced). And don't just move it to your init
method as that has the same issue. And in your init
method you need to call super
before you try to set and instance variable content.
or this:
[*parseError release];
(because the error isn't yours to release).
Other than that your code is fine. This is asynchronous by its nature because it's using delegate methods, and the top level documentation for NSURLConnection
describes how it is an asynchronous operation.
didFailWithError:
will be called with any error related to the URL connection handling / server response.