Target-action

Timers use a target-action mechanism. You create a timer with a time interval, a target, and an action. After the interval has elapsed, the timer sends the action message to its target.

You are going to add an instance of NSTimer to your program. Every two seconds, the timer will send the action message to its target. You will also create a class named BNRLogger. An instance of that class will be the timer’s target.

Figure 27.1  BNRLogger is the target of the NSTimer

BNRLogger is the target of the NSTimer

Create a new file: an Objective-C class called BNRLogger that is a subclass of NSObject.

In BNRLogger.h, declare a property that holds a date, ...

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.