Challenge: using a block with NSNotificationCenter

In Chapter 27, you used NSNotificationCenter’s addObserver:selector:name:object: method to register to receive callbacks via your zoneChange: method. Update that exercise to use the addObserverForName:object:queue:usingBlock: method instead.

This method takes a block as an argument and then executes the block instead of calling back to your object when the specified notification is posted. This means that your zoneChange: method will never be called. The code that was inside this method will instead be in the block.

The passed-in block should take a single argument (an NSNotification *) and return nothing, just as the zoneChange: method does.

Pass nil as the argument for queue:; this ...

Get Objective-C Programming: The Big Nerd Ranch Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.