Why should I choose GCD over NSOperation and blocks for high-level applications?

前端 未结 5 1206
既然无缘
既然无缘 2020-12-07 12:19

Apple\'s Grand Central Dispatch reference says:

\"...if your application needs to operate at the Unix level of the system—for example, if it needs t

5条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-07 13:04

    I've actually just been reading 'round about this, and, I'm sure it will come as know surprise, opinions differ.

    I can't think of a case where you'd have to use GCD over NSOperation, but that doesn't mean such a case doesn't exist. I, however, agree with a general sentiment in terms of best-practice coding:

    If you have a couple tools that suit the job (and in this case, you've got NSOperation vs a GCD block), use the class with the highest level of abstraction (ie, the highest level API). Not only is it typically easier to use/less code, you'll also gain from potential future enhancements introduced to the higher level APIs.

提交回复
热议问题