Graphics Programs Reference
In-Depth Information
the next chapter, so the accessor methods for BNRItem are very simple. In BNRItem.m ,
add the following code.
#import "BNRItem.h"
@implementation BNRItem
- (void)setItemName:(NSString *)str
{
itemName = str;
}
- (NSString *)itemName
{
return itemName;
}
- (void)setSerialNumber:(NSString *)str
{
serialNumber = str;
}
- (NSString *)serialNumber
{
return serialNumber;
}
- (void)setValueInDollars:(int)i
{
valueInDollars = i;
}
- (int)valueInDollars
{
return valueInDollars;
}
- (NSDate *)dateCreated
{
return dateCreated;
}
@end
Notice that the setter methods assign the appropriate instance variable to point at the in-
coming object, and the getter methods return a pointer to the object the instance variable
points at. (For valueInDollars , the setter just assigns the passed-in value to the in-
stance variable, and the getter just returns the instance variable's value.)
Build your application (without running) to ensure that there are no compiler errors or
warnings. To build only, select Product Build or use the shortcut Command-B.
Now that your accessors have been declared and defined, you can send messages to
BNRItem instances to get and set their instance variables. Let's test this out. In main.m ,
import the header file for BNRItem and create a new BNRItem instance. After it is cre-
ated, log its instance variables to the console.
Search WWH ::




Custom Search