Which tasks would be better suited to using NSOperation as opposed to using GCD when programming for the iPhone?
To me they seem to do the same thing. I can’t see the strengths and weaknesses one has over the other.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
NSOperationis built on top of GCD, so the question is more about whether you useNSOperationor pass a block directly to GCD.An
NSOperationis bulky and needs more boiler-plate codes to set it up, but it has a lot more functionality. You can create the sameNSOperationsubclass in various parts of your code and put them into the queue and run it.Passing a block to GCD by e.g.
dispatch_asyncis quick and disposable. You typically don’t reuse a block anywhere else; you just set up a block which is executed only at that point of the code, passes it to the GCD or other APIs, and quickly go on.So each has its merits.