application crashes when appendString for NSMutableString is used
===

I'm new to objective-c and I decided to start by working through Stanford's CS193s 2010F Session's lectures/assignments.

I was working on the second assignment, and I was stuck when I had to return a NSString that combines(concatenates) every strings inside NSMutableArray. (The MutableArray consists only NSString at its each indices)


My approach was to use a for loop to pass through the MutableArray's indicies(in the code below, the MutableArray is 'anExpression' with type 'id'). I declared a NSMutableString and added NSString at each indices of 'anExpression' array. Here is the code:

    + (NSString *)descriptionOfExpression:(id)anExpression{
      NSMutableString *result = [NSMutableString string];
      
      for (int i = 0;i<[anExpression count];i++){
        [result appendString:[anExpression objectAtIndex:i]];
      }
  
      return result;
    }

However, at

     [result appendString:[anExpression objectAtIndex:i]];

xcode crashes with following error statements:

    2012-07-17 01:44:51.014 Calculator[9470:f803] -[__NSCFNumber length]: unrecognized selector sent to instance 0x68732c0
    2012-07-17 01:44:51.015 Calculator[9470:f803] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFNumber length]: unrecognized selector sent to instance 0x68732c0'
    *** First throw call stack:
    (0x13ca022 0x155bcd6 0x13cbcbd 0x1330ed0 0x1330cb2 0x12d2d18 0x13460d7 0x1397a8d 0x3a50 0x27ed 0x13cbe99 0x1714e 0x170e6 0xbdade 0xbdfa7 0xbd266 0x3c3c0 0x3c5e6 0x22dc4 0x16634 0x12b4ef5 0x139e195 0x1302ff2 0x13018da 0x1300d84 0x1300c9b 0x12b37d8 0x12b388a 0x14626 0x1ed2 0x1e45 0x1)
    terminate called throwing an exception
 
I looked through apple's developer's document, saw 'NSString stringWithFormat:' method, and decided to use this method instead:

    + (NSString *)descriptionOfExpression:(id)anExpression{
      NSMutableString *result = [NSMutableString string];
  
      for (int i = 0;i<[anExpression count];i++){
        [result appendString:[NSString stringWithFormat:@"%@",[anExpression objectAtIndex:i]]];
      }
      
      return result;
    }

and it works now.

now I'm confused why second code works but the first doesn't.
I thought appending string only fails(and crashes) when it's passed a nil...

Is there something I'm missing?

Thank you in advance :)