Graphics Programs Reference
In-Depth Information
#import <Foundation/Foundation.h>
@interface BNRItem : NSObject
{
NSString *itemName;
NSString *serialNumber;
int valueInDollars;
NSDate *dateCreated;
}
- (void)setItemName:(NSString *)str;
- (NSString *)itemName;
- (void)setSerialNumber:(NSString *)str;
- (NSString *)serialNumber;
- (void)setValueInDollars:(int)i;
- (int)valueInDollars;
- (NSDate *)dateCreated;
@end
(For those of you with some experience in Objective-C, we'll talk about properties in the
next chapter.)
Now that these accessors have been declared, they need to be defined in the implementa-
tion file. Select BNRItem.m in the project navigator to open it in the editor area.
At the top of any implementation file, you must import the header file of that class. The
implementation of a class needs to know how it has been declared. (Importing a file is the
same as including a file in the C language except you are ensured that the file will only be
included once.)
After the import statement is the implementation block that begins with the @imple-
mentation keyword followed by the name of the class that is being implemented. All
of the method definitions in the implementation file are inside this implementation block.
Methods are defined until you close out the block with the @end keyword.
When you created this class, the template you used may have inserted methods for you.
However, we want to start from scratch. Using boilerplate methods before you understand
what they do keeps you from learning how things actually work. In BNRItem.m , delete
everything that the template may have added between @implementation and @end .
Your file should look like this:
#import "BNRItem.h"
@implementation BNRItem
@end
Now we can define some methods of our own - starting with the accessor methods for the
variables you declared in BNRItem.h . We're going to skip memory management until
Search WWH ::




Custom Search