Gold Challenge - Getting Started


#1

So I’m trying to approach this book as if I were in school and really learning the subject matter. Because of that I am trying to avoid peaking into other posts and seeing what they have done for this challenge. I understand most of Chapter 2, but am having a bit of difficulty getting started with the Gold Challenge and have two questions.

First, I’m not sure if the subclass of BNRItem will be creating the BNRItem and its respective values OR is it just creating some array like we did in main() just now it is being created in the subclass’ methods? After typing this, I’m thinking that since BNRContainer is a subclass, it also has BNRItem, so the code, methods are included - inherited. So in main() I could send a message to BNRContainer and containerName, the array, and all of the BNRItems would be created through the BNRContainer subclass. Maybe I’m still a little confused.

My second question, when the authors want the name of the container, is this the name of the array or is it an NSString * containerName which doesn’t hold anything, it’s just a name?

Thanks in advance.


#2

OK. SO I have a solution. A question I have revolves around the description method. My code is show below. Why can’t I use the for() statement that is commented out rather than the one being used? I tried the unused one I used but it didn’t print the items in the array.

for (int i = 0; i < [containerArray count]; i++)
{
    BNRItem *currentItem = [containerArray objectAtIndex:i];
    descriptionString = [descriptionString stringByAppendingString:[NSString stringWithFormat:@"%@ (%@) %@ $%d \n", [currentItem itemName], [currentItem serialNumber], [currentItem dateCreated], [currentItem valueInDollars]]];
}

//for (BNRItem *item in containerArray)
//{
// descriptionString = [descriptionString stringByAppendingString:[NSString stringWithFormat:@"%@ (%@) %@ $%d \n",
// itemName,
// serialNumber,
// dateCreated,
// valueInDollars ]];
//}