Note that there are some explanatory texts on larger screens.

plurals
  1. POCoalescing while using NSNotificationQueue
    text
    copied!<p>I wrote the following code to perform coalescing using NSNotificationQueue.I want to post only one notification even if the event occurs multiple times.</p> <pre><code>- (void) test000AsyncTesting { [NSRunLoop currentRunLoop]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(async000:) name:@"async000" object:self]; [[NSNotificationQueue defaultQueue] enqueueNotification:[NSNotification notificationWithName:@"async000" object:self] postingStyle:NSPostWhenIdle coalesceMask:NSNotificationCoalescingOnName forModes:nil]; while (i&lt;2) { [[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:1.0]]; NSLog(@"Polling..."); i++; } } - (void) async000:(NSNotification*)notification; { NSLog(@"NSNotificationQueue"); } </code></pre> <p>Everytime on calling the method 'test000AsyncTesting',the notifications with same name are added to the queue. As per the concept of coalescing,if queue has any number of notifications but with same name then it will be posted only once. But when I run my code,'async000:'is called multiple times which is exactly equal to the number of notifications added to the NSNotificationQueue.I think the coalescing is not working.<br> For me, execution of code remains same in both of these cases:</p> <p>Case 1: [[NSNotificationQueue defaultQueue] enqueueNotification:[NSNotification notificationWithName:@"async000" object:self] postingStyle:NSPostWhenIdle coalesceMask:NSNotificationCoalescingOnName forModes:nil];</p> <p>Case 2: [[NSNotificationQueue defaultQueue] enqueueNotification: [NSNotification notificationWithName:@"async000" object:self] postingStyle:NSPostWhenIdle];</p> <p>Please tell the error in my code.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload