The Receptionist Pattern is a design pattern that provides a way to redirect an event from one thread to another thread for it to be processed. The magic of using Key-Value Observing (KVO). More info: Receptionist
I understand the concept and the code. What I am struggling with is understanding how to accomplish the following:
“One common situation where the Receptionist pattern is useful is
key-value observing. In key-value observing, changes to the value of
an model object’s property are communicated to observers via KVO
notifications. However, changes to a model object can occur on a
background thread. This results in a thread mismatch, because changes
to a model object’s state typically result in updates to the user
interface, and these must occur on the main thread. In this case, you
want to redirect the KVO notifications to the main thread. where the
updates to an application’s user interface can occur.”
Here is a snippet of what is described in the sample implementation.
The client object supplies the block code that updates the user
interface when it creates a receptionist object, as shown in Listing
4-4. Note that when it creates the receptionist object, the client
passes in the operation queue on which the block is to be executed, in
this case the main operation queue.
RCReceptionist *receptionist = [RCReceptionist receptionistForKeyPath:@"value" object:model queue:mainQueue task:^(NSString *keyPath, id object, NSDictionary *change) {
NSView *viewForModel = [modelToViewMap objectForKey:model];
NSColor *newColor = [change objectForKey:NSKeyValueChangeNewKey];
[[[viewForModel subviews] objectAtIndex:0] setFillColor:newColor];
}];
Simply asked, how does one acquire the main operation queue (aka ‘mainQueue’) off the main thread? Can someone help me connect the dots here please.
To grab the main operation queue: