Objective C - performSelectorInBackground V.S detachNewThreadSelector?

元气小坏坏 提交于 2019-12-06 11:50:09

问题


Both detachNewThreadSelector and performSelectorInBackground are used to call a method in the background.

Is there any difference between the 2 methods? or do they both work the same way?


回答1:


They're both essentially the same but slightly different paradigms. Behind the scenes they do exactly the same thing. The only real difference is that -[performSelectorInBackground:withObject:] follows all the other performSelector style methods in that they're defined on NSObject and you actually message that defines the selector you wish to perform.

In general, you should almost never have to call either of these methods. Favor using Grand Central Dispatch or NSOperation and NSOperationQueue to factor out expensive operations on other threads. Both GCD and the NSOperation classes give you memory management, thread pool management and many other things you'll miss using the older style dispatch methods.



来源:https://stackoverflow.com/questions/5148980/objective-c-performselectorinbackground-v-s-detachnewthreadselector

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!