iPhone - May an async NSURLConnection HTTP response interfer with running process?
I have a request :
[NSURLConnection connectionWithRequest:urlRequest delegate:self];
that is launched.
When I receive at any time :
- (void)connectionDidFinishLoading:(NSURLConnection*)connection
I change the content of an array (remove or add items).
In another part of my program, I have to parse that array to work with its content.
So the question is : while I'm working with the content of the array ("for xxx in array" loop), may the response of the server (that can come at any time) cause the code of connectionDidFinishLoading
change that array, and make the whole thin开发者_JAVA百科g crash ?
Yes and it will cause your app to crash. You can either work with a copy of the array that is being modified by the NSURLConnection delegate method OR wait for the method to finish before iterating through the items in your array.
Maybe block that particular operation while there is an active NSURLConnection so the rest of your UI is still usable.
精彩评论