Big Nerd Ranch Guide 中的作业说:
Silver Challenge: Another initializer
Create another initializer method for BNRItem.
This initializer is not the designated initializer of BNRItem.
It takes an NSString that identifies the itemName of the item and an
NSString that identifies the serialNumber.
我不确定我是否正确实施了它。它是否正确?
BNRItem.h
- (id)initWithItemName:(NSString *)name
valueInDollars:(int)value
serialNumber:(NSString *)aNumber;
// I added this for new initializer
- (id)initWithItemName:(NSString *)name serialNumber:(NSString *)aNumber;
BNR项目.m
- (id)initWithItemName:(NSString *)name valueInDollars:(int)value serialNumber:(NSString *)aNumber
{
self = [super init];
if (self)
{
[self setItemName:name];
[self setSerialNumber:aNumber];
[self setValueInDollars:value];
dateCreated = [[NSDate alloc] init];
}
return self;
}
// Added the implementation for the new initializer
- (id) initWithItemName:(NSString *)name serialNumber:(NSString *)aNumber
{
return [self initWithItemName:name valueInDollars:0 serialNumber:aNumber];
}