Is NSNotificationCenter thread safe?

后端 未结 2 1353
臣服心动
臣服心动 2021-02-13 16:52

Can I post a notification in a given queue and receive it on another? I want to use notifications to communicate different queues, but I\'m not sure if this is safe...

2条回答
  •  情书的邮戳
    2021-02-13 17:04

    No.

    Apple's docs on the subject say: "Regular notification centers deliver notifications on the thread in which the notification was posted. [...] At times, you may require notifications to be delivered on a particular thread that is determined by you instead of the notification center. [...] In these cases, you must capture the notifications as they are delivered on the default thread and redirect them to the appropriate thread."

    The following documentation from Apple might help: https://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/Notifications/Articles/Threading.html#//apple_ref/doc/uid/20001289-CEGJFDFG

提交回复
热议问题