Having done something similar to OR in RubyCocoa myself I can say that
it's safer for OR to expect the user to run the code in a separate
thread. It makes more sense to me than trying it the other way.
I played around with different approaches to handle this, since it was
of course the first thing that you come across when dealing with
network requests. I used both a normal thread (NSThread) and an
NSLoadOperationQueue to handle the network tasks in the background.
You have to do more work to ensure that you're always updating the GUI
from the main thread, when you're handling events from the queue or
the thread, but that's what performSelectorOnMainThread is for.
Cheers, Mathias
--
http://paperplanes.de
http://twitter.com/roidrage
This is the approach that we currently take, though it's something we
are eager to improve upon.
In order to keep the UI responsive, my preference is to use the
NSOperationQueue. I'll create a ticket to add this
as part of the sample application, and possibly as part of the framework.
Here is some sample code for now: http://gist.github.com/66593
The above linked gist sets up a single operation queue in the app
delegate and then makes use of that queue to
load the list of people from ObjectiveResource and refresh the table
view as an NSOperation.
Note the use of "performSelectorOnMainThread:" in the method that gets
run as an NSOperation. This is because the UITableView
"reloadData" method needs to be called in the UI thread.
Also note that the "people" property should be declared as an atomic
property since it will now be accessed from multiple threads. One
possible way around that would be to call the setter using the same
"performSelectorOnMainThread" message used for the tableView.