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 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access