Ning Su Ning Su - 16 days ago 7
iOS Question

Notifications in Multiple Thread iOS

I have found that when I want to deliver Notifications to particular threads, there is a sample from Apple.

https://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/Notifications/Articles/Threading.html#//apple_ref/doc/uid/20001289-CEGJFDFG

In this article, Apple suggests that using a machport to monitor the thread which we want to process the notification.

- (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;
}
}


My question is: if I get the notification and I use
dispatch_async
to process the notification, does it has a different appearance?

dispatch_async(dispatch_get_main_queue(), ^{
// Process the notification here;
});

Answer

the simple answer is : no difference

I also noticed the apple suggested link is Updated: 2009-08-18. it seems to already outdated. GCD is a more powerful and convenient way to achieve multi-thread work.