Graphics Programs Reference
In-Depth Information
- (NSString *)itemName;
- (void)setSerialNumber:(NSString *)str;
- (NSString *)serialNumber;
- (void)setValueInDollars:(int)i;
- (int)valueInDollars;
- (NSDate *)dateCreated;
- (void)setContainedItem:(BNRItem *)i;
- (BNRItem *)containedItem;
- (void)setContainer:(BNRItem *)i;
- (BNRItem *)container;
@property (nonatomic) BNRItem *containedItem;
@property (nonatomic) BNRItem *container;
@property (nonatomic) NSString *itemName;
@property (nonatomic) NSString *serialNumber;
@property (nonatomic) int valueInDollars;
@property (nonatomic) NSDate *dateCreated;
@end
Unfortunately, nonatomic is not the default option, so you will always need to expli-
citly declare your properties to be nonatomic .
The second attribute of a property is either readwrite or readonly . A readwrite
property declares both a setter and getter, and a readonly property just declares a getter.
The default option for this attribute is readwrite . This is what we want for all of
BNRItem 's properties with the exception of dateCreated , which should be
readonly . In BNRItem.h , declare dateCreated as a readonly property so that
no setter method is declared for this instance variable.
@property (nonatomic , readonly ) NSDate *dateCreated;
The final attribute of a property describe its memory management. The most common op-
tions tell us whether the accessed instance variable has a strong or weak reference to
the object it points to. The default option is assign , which is for properties like
valueInDollars that do not point to an object. The rest of BNRItem 's instance vari-
ables are all strong references to objects with the exception of container , which is
weak. Add the strong attribute option to the appropriate properties and weak to the
container property.
@property (nonatomic , strong ) BNRItem *containedItem;
@property (nonatomic , weak ) BNRItem *container;
@property (nonatomic , strong ) NSString *itemName;
@property (nonatomic , strong ) NSString *serialNumber;
@property (nonatomic) int valueInDollars;
@property (nonatomic, readonly , strong ) NSDate *dateCreated;
Search WWH ::




Custom Search