CoreData之performBlock 和 performBlockAndWait

两个函数的区别是performBlock不会阻塞运行的线程,相当于异步操作,performBlockAndWait会阻塞运行线程,相当于同步操作

performBlock 和 performBlockAndWait 的区别:

performBlock : Asynchronously performs a given block on the receiver’s queue.
performBlockAndWait : Synchronously performs a given block on the receiver’s queue.

stack overflow解释如下:

The main point is that when you call any *performBlock **or GCD function, you should not expect it to run on any particular thread (except something tied to the main thread) because queues are not threads, and only the main queue will run blocks on a specific thread.

When calling the core data performBlockAndWait the block will execute in the calling thread (but will be appropriately synchronized with everything submitted to the queue).

你可能感兴趣的:(CoreData之performBlock 和 performBlockAndWait)