Hello,
I am working on an iPhone app that does some web scraping and podcast loading. I have successfully coded a first version by means of high-level APIs like NSString's stringWithContentsOfURL and now I would like to make my code non-blocking.
I have read the CFNetwork Programming Guide and I am aware of the techniques described there.
However, I am wondering if it wouldn't be easier (and robust, and readable etc) to shove my code into a thread. The lengthy/blocking code is located in my controller's viewDidLoad method. Essentially it builds an array of title/URL pairs for the podcasts, to be used in turn for the cells of a TableView.
The main thread would return either the number of rows or just zero. As the worker thread would grow the array, it would notify the main thread that would tell the view to refresh itself and call the controller. The model in this case is obviously the array.
If the user gives up and leaves the view, then kill the thread.
Is this approach sound ? Is it safe to kill the worker thread when it is posting HTTP requests and running regexes with callback blocks ? How do I tell the TableView to refresh itself ? Are there documents at developer.apple.com that I should read ?
Thanks to all who will feel like helping this rookie ;-)
Jean-Louis
I am working on an iPhone app that does some web scraping and podcast loading. I have successfully coded a first version by means of high-level APIs like NSString's stringWithContentsOfURL and now I would like to make my code non-blocking.
I have read the CFNetwork Programming Guide and I am aware of the techniques described there.
However, I am wondering if it wouldn't be easier (and robust, and readable etc) to shove my code into a thread. The lengthy/blocking code is located in my controller's viewDidLoad method. Essentially it builds an array of title/URL pairs for the podcasts, to be used in turn for the cells of a TableView.
The main thread would return either the number of rows or just zero. As the worker thread would grow the array, it would notify the main thread that would tell the view to refresh itself and call the controller. The model in this case is obviously the array.
If the user gives up and leaves the view, then kill the thread.
Is this approach sound ? Is it safe to kill the worker thread when it is posting HTTP requests and running regexes with callback blocks ? How do I tell the TableView to refresh itself ? Are there documents at developer.apple.com that I should read ?
Thanks to all who will feel like helping this rookie ;-)
Jean-Louis