I've been looking for some concrete scenarios for when NSOperation
on the iPhone is an ideal tool to use in an application. To my understanding, this is a wrapper around writing your own threaded
code. I haven't seen any Apple demo apps using it, and I'm wondering if I'm missing out on a great tool instead of using NSThread
.
The ideal solution here would be to describe a use-case scenario for NSOperation
and how you would use it to solve your problem(s).
Overview. An operation queue invokes its queued NSOperation objects based on their priority and readiness. After you add an operation to a queue, it remains in the queue until the operation finishes its task. You can't directly remove an operation from a queue after you add it. Note.
GCD is a low-level C-based API that enables very simple use of a task-based concurrency model. NSOperation and NSOperationQueue are Objective-C classes that do a similar thing. NSOperation was introduced first, but as of 10.5 and iOS 2, NSOperationQueue and friends are internally implemented using GCD .
An abstract class that represents the code and data associated with a single task.
NSOperationQueue can be more suitable for long-running operations that may need to be cancelled or have complex dependencies. GCD dispatch queues are better for short tasks that should have minimum performance and memory overhead.
Cocoa Is My Girlfriend has a good tutorial on the use of NSOperation
and NSOperationQueue
. The tutorial makes use of NSOperation
to download several webpages simultaneously in separate threads.
Also, see this article from Mac Research.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With