Silver Challenge solution


#1

This is how I worked out the Silver Challenge, can anyone indicate if it’s right? (since I see some solutions here who treat the initializer as a designated initializer)

BNRItem.h

-(id) initWithItemName: (NSString *)name
          serialNumber: (NSString *) sNumber;

BNRItem.m

-(id)initWithItemName:(NSString *)name serialNumber:(NSString *)sNumber
{
    return [self initWithItemName:name valueInDollars:0 serialNumber:sNumber];
}

Thanks in advance!


#2

Can anyone confirm that this is the correct way? :wink:


#3

I’m confused. Do you have two initializers with the same name?

It looks like you are calling the original initWithItemName method that had 3 parameters, but you are calling it with a new initializer that has 2 parameters and is using the same name…


#4

Yep, I did it basically the same way it is explained on page 51 in the book (if I interpreted it right :confused: )


#5

Pippah: Yes, your solution is correct. You can verify that it works correctly by actually calling it, for example, from RandomPossessions main.m.