iPhone - 异步 NSURLConnection HTTP 响应可能会干扰正在运行的进程吗?
我有一个请求:
[NSURLConnection connectionWithRequest:urlRequest delegate:self];
已启动。
当我随时收到:
- (void)connectionDidFinishLoading:(NSURLConnection*)connection
我更改数组的内容(删除或添加项目)。
在程序的另一部分,我必须解析该数组才能处理其内容。
所以问题是:当我处理数组的内容时(“for xxx in array”循环),服务器的响应(可能随时出现)可能会导致 connectionDidFinishLoading
的代码code> 更改该数组,并使整个事情崩溃?
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 thing crash ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
是的,这会导致您的应用程序崩溃。您可以使用 NSURLConnection 委托方法正在修改的数组的副本,或者等待该方法完成,然后再迭代数组中的项目。
当存在活动的 NSURLConnection 时,可能会阻止该特定操作,因此 UI 的其余部分仍然可用。
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.