开发者

Core Data blocking UI after asynchronous NSURLConnection didLoadResource on iPhone

开发者 https://www.devze.com 2022-12-27 12:30 出处:网络
Each time somebody touches a row inside a UITableView, I\'m kicking off a series of asynchronous NSURLConnections, that download data and then parse and save that data into Core Data.

Each time somebody touches a row inside a UITableView, I'm kicking off a series of asynchronous NSURLConnections, that download data and then parse and save that data into Core Data.

The problem is that when I do this, the UI is responsive during the data download, but as soon as the parsing and saving begins, the UI becomes non-responsive.

The NSURLConnection is wrapped inside a class, that implements the NSURLConnection protocol, and when the NSURLConnection is fires didLoadResource, it kicks off a DataAdapter class that handles the parsing and saving. I'm 开发者_JS百科thinking thats the cause of my UI blocking.

Has anyone dealt with this before? What are my options? Put the DataAdapter into an NSOperation?


By default, Core Data operates on the main thread which is the same thread used by the UI. You need to either create a separate context in another thread or (easier) wait until the down load is finished before moving the information into Core Data. Right now, Core Data is freezing the main thread and the interface while it waits for some data to finish downloading.

See Multithreading with Core Data.

0

精彩评论

暂无评论...
验证码 换一张
取 消