美文网首页
CoreData之performBlock 和 performB

CoreData之performBlock 和 performB

作者: 三秋树下 | 来源:发表于2017-08-07 15:37 被阅读288次

    两个函数的区别是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 和 performB

          本文链接:https://www.haomeiwen.com/subject/yftvcxtx.html