1) Why should we use NSOperationQueue?
2) What is advantage when we use it?
3) Can we achieve multiple synchronous web operations through NSOperationQueue at the same time?
4) Why do we use NSOperationQueue in lazy-loading of UITableView? Is it not possible to do it without NSOperationQueue?
Why should we use NSOperationQueue?
You should use NSOperationQueue to achieve concurrency when the unit of work is an NSOperation or one of its subclasses. Or with other API's that require an NSOperationQueue, e.g. the addObserverForName:object:queue:usingBlock: method on NSNotificationCenter
What is advantage when we use it?
When the unit of work to perform asynchronously can be encapsulated in an NSOperation object. Perhaps you're asking what is the advantage over other asynchronous API's? There it's largely, but not entirely, a question of the level of abstraction you need and are comfortable with managing. As one author put it: "Always use the highest-level abstraction available to you, and drop down to lower-level abstractions when measurement shows that they are needed."
Can we achieve multiple synchronous web operations through NSOperationQueue at the same time?
Of course. See numerous tutorials online that address this very subject. Like this one by the estimable Marcus Zarra.
Why do we use NSOperationQueue in lazyloading of Tableview?
For the same reason as you would use any concurrent technique. To make the work faster and/or avoid blocking the UI. In the case you cite, it's chiefly about not blocking the UI with a long-running task.
Is it not possible to do it without NSOperationQueue?
Sure it's possible. NSThread, GCD, etc.
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