Triggering the notification explicitly

The system can automatically inform the observer if you use the accessor method to set the property. What if you, for some reason, choose not to use the accessor? You can explicitly let the system know that you are changing a property. Change your BNRLogger.m so that it does not use the accessor to set lastName:

-​ ​(​v​o​i​d​)​u​p​d​a​t​e​L​a​s​t​T​i​m​e​:​(​N​S​T​i​m​e​r​ ​*​)​t​
{​
 ​ ​ ​ ​N​S​D​a​t​e​ ​*​n​o​w​ ​=​ ​[​N​S​D​a​t​e​ ​d​a​t​e​]​;​
 ​ ​ ​ ​_​l​a​s​t​T​i​m​e​ ​=​ ​n​o​w​;​
 ​ ​ ​ ​N​S​L​o​g​(​@​"​J​u​s​t​ ​s​e​t​ ​t​i​m​e​ ​t​o​ ​%​@​"​,​ ​s​e​l​f​.​l​a​s​t​T​i​m​e​S​t​r​i​n​g​)​;​
}​

Build and run the program. Notice that the Observer never gets told that _lastTime has changed. ...

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.