多线程iOS中的通知
我发现,当我想向特定线程发送通知时,有一个来自苹果的示例 在本文中,Apple建议使用machport来监视我们想要处理通知的线程多线程iOS中的通知,ios,objective-c,multithreading,notifications,Ios,Objective C,Multithreading,Notifications,我发现,当我想向特定线程发送通知时,有一个来自苹果的示例 在本文中,Apple建议使用machport来监视我们想要处理通知的线程 - (void)processNotification:(NSNotification *)notification { if ([NSThread currentThread] != notificationThread) { // Forward the notification to the correct thread.
- (void)processNotification:(NSNotification *)notification {
if ([NSThread currentThread] != notificationThread) {
// Forward the notification to the correct thread.
[self.notificationLock lock];
[self.notifications addObject:notification];
[self.notificationLock unlock];
[self.notificationPort sendBeforeDate:[NSDate date]
components:nil
from:nil
reserved:0];
}
else {
// Process the notification here;
}
}
我的问题是:如果我收到通知并使用dispatch\u async
处理通知,它是否具有不同的外观
dispatch_async(dispatch_get_main_queue(), ^{
// Process the notification here;
});
答案很简单:没有区别 我还注意到苹果建议的链接已经更新:2009-08-18。它似乎已经过时了。GCD是实现多线程工作的一种更强大、更方便的方法