Golden challenge: description is null, why?


#1

Firstly, I think this “Big Nerd Ranch Guide” is so good, it is one of best code learning books.
Then I have so problem, please read as follow code:

-(NSString *)description { NSString *dString=[[NSString alloc] init]; NSString *dString1=[[NSString alloc] init]; int valueTotal=0; int i=1; for (id item in itemList) { i++; [dString1 stringByAppendingString:[NSString stringWithFormat:@"No.%d item description ---- \n Name:%@ Serial:%@ Value:%d Date:%@",i,[item itemName],[item serialNumber],[item valueDollars],[item dateCreated]]]; valueTotal=valueTotal+[item valueDollars]; [dString stringByAppendingString]; } NSString *totalValueString=[NSString stringWithFormat:@"\n total value:$%d",valueTotal]; return [dString stringByAppendingString:totalValueString]; }

The dString and dString1 is null, I don’t understand since I have init dString and dString1, but it
is OK if I use as following code:

[code]-(NSString *)description
{
NSString *dString=[[NSString alloc] init];

int valueTotal=0;
int i=1;
for (id item in itemList) {
    i++;
   dString=[dString stringByAppendingString:[NSString stringWithFormat:@"No.%d item description ---- \n Name:%@  Serial:%@  Value:%d  Date:%@",i,[item itemName],[item serialNumber],[item valueDollars],[item dateCreated]]];
    valueTotal=valueTotal+[item valueDollars];
}
NSString *totalValueString=[NSString stringWithFormat:@"\n total value:$%d",valueTotal];
return [dString stringByAppendingString:totalValueString];

}
[/code]

Thank for any comments.