What are the different ways for calling my method on separate thread?

后端 未结 2 840
温柔的废话
温柔的废话 2020-12-23 11:39

I have some data calculation method (let it be \"myMethod:\"), and I want to move the call to another thread because I don\'t want to block my main UI functionality. So, sta

2条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-23 12:19

    Here is an updated answer to this old question. NSOperations are implemented with libdispatch for both macos and ios now. They have been for some time. The preferred way to call to a different thread is with one of libdispatch or NSOperations. The main idea to keep in mind is "Quality of Service", or "QOS". A QOS is something assigned to a thread, and when you assign it to a dispatch queue, and NSOperationQueue, or an NSOperation, you are essentially saying, "I want this to run on a thread with this QOS assigned." The special case is the main thread.

    There might still be some cases to use NSThread, but I haven't had any for a long time.

提交回复
热议问题