tags:

views:

247

answers:

2

Is it a good idea to load images (1 block each) through Grand Central Dispatch in iOS 4.0? (for use in a UITableView)

Why is a runloop preferred by Apple, as illustrated in the WWDC video sessions 207 and 208?

+1  A: 

I haven't watched those videos yet, but here is what Chris Hanson (Apple Engineer) says about GCD vs NSOperation

Always use the highest-level abstraction available to you, and drop down to lower-level abstractions when measurement shows that they are needed.

In other words, you should be using NSOperations to do asynchronous processing (such as loading images for a table view) unless you have a good and necessary reason to go for GCD.

Matt Long
In this case, the overhead for creation of an NSOperation and placement of it in a queue may add up across all the table view rows, so the more lightweight blocks might be preferable. Blocks and GCD might also simplify his code for this task.
Brad Larson
+2  A: 

The point being made in those videos was that Foundation networking does not integrate well with Grand Central Dispatch right now, so if you want to do Foundation-based networking a runloop is your best bet for avoiding the problems of traditional threads. However, in Session 206 - "Introducing Blocks and Grand Central Dispatch on iPhone", you'll see that they show an example of how to use GCD for just this purpose.

Me, I prefer GCD because of the elegance of the code and because (as they state in those videos) it is the way of the future.

Brad Larson
GCD doens't work well with Foundation-based networking? Than what can one use? and, how does it differ from Foundation-based networking API? Thank you
Henry
@Henry - When working with GCD, I believe that you would use the CFNetwork functions, rather than classes like NSURLConnection. The runloop-based approach in WWDC 2010 Session 208 is pretty interesting, though.
Brad Larson
thanks Brad, so what would you recommend a newbie to use? GCD w/ CFNetwork functions, or runloop with NSURLConnection with runloop?
Henry
and where does NSOperation fit in the whole picture? thank you!
Henry
@Henry - Honestly, for a newbie I'd suggest looking at a wrapper like ASIHTTPRequest: http://allseeing-i.com/ASIHTTPRequest/ . I've only started integrating GCD with my applications (although I use NSOperation all the time), and the runloop approach is fairly new to me. For general concurrency tasks, I'd read up on NSOperation first, then GCD.
Brad Larson
Thanks, one thing I don't understand about the runloop approach is, how can I download 2 images at a time to reduce latency?
Henry
@Henry - Again, I've not worked with the runloop-based approach. I highly recommend watching the session 208 video closely to understand Apple's take on this.
Brad Larson