title: NSArray&NSMutableArray confusion
body: <p>I'm stuck at a challenge of some book. </p>
  
  <p>I created a NSArray property named "holdings" in h.file to be accessed, and NSMutableArray instance valuable named "_holdings" at the class extension in m.file.
  It's because other objects are not allowed to access the array.</p>
  
  <p>When I compiled it , the error message came out, and said "....-[__NSArrayI addObject:]: unrecognized selector sent to instance /Users/Toshikiinami/Desktop/Screen Shot 2014-05-13 at 21.16.09.png0x10010b7b0..."<img src="https://i.stack.imgur.com/qgPrQ.png" alt="enter image description here"></p>
  
  <p>I set the _holdings as NSMutableArray but this error is saying "_holdings is an NSArray instance", that is addObject: method doesn't work.</p>
  
  <p>I appreciate any help :) Thank you!</p>
  
  <p>BNRPortfolio.h</p>
  
  <pre><code>#import &lt;Foundation/Foundation.h&gt;
  #import "BNRStockHolding.h"
  
  @interface BNRPortfolio : NSObject
  
  
  @property(nonatomic, copy) NSArray *holdings;
  
  
  - (float)totalValue;
  - (void)addStock:(BNRStockHolding *)stockHolding;
  - (void)removeStock:(unsigned int) i;
  
  
  
  
  @end
  </code></pre>
  
  <p>BNRPortfolio.m</p>
  
  <pre><code>#import "BNRPortfolio.h"
  #import "BNRStockHolding.h"
  
  @interface BNRPortfolio()
  {
      NSMutableArray *_holdings;
  
  }
  @end
  
  @implementation BNRPortfolio
  
  - (void)holdings:(NSArray *)a
  {
      _holdings = [a mutableCopy];
  }
  
  - (NSArray *)setHoldings
  {
  
      return [_holdings copy];
  
  }
  
  - (float)totalValue
  {
      float total = 0;
  
      for (int i = 0; i &lt; 3; i++)
      {
          float currentValue = [_holdings[i] valueInDollars];
          total += currentValue;
      }
  
      return total;
  }
  
  - (void)addStock:(BNRStockHolding *)stockHolding
  {
      if (!_holdings)
      {
          _holdings = [[NSMutableArray alloc] init];
      }
  
      [_holdings addObject:stockHolding];
  
  
  }
  
  - (void)removeStock:(unsigned int)i
  {
      if (_holdings)
      {
          [_holdings removeObjectAtIndex:i];
  
      }
  
  }
  
  @end
  </code></pre>
  
  <p>main.m</p>
  
  <pre><code>#import &lt;Foundation/Foundation.h&gt;
  #import "BNRStockHolding.h"
  #import "BNRForeignStockHolding.h"
  #import "BNRPortfolio.h"
  
  
  int main(int argc, const char * argv[])
  {
  
      @autoreleasepool {
  
          BNRStockHolding *stock1 = [[BNRStockHolding alloc]init];
          BNRStockHolding *stock2 = [[BNRStockHolding alloc] init];
          BNRForeignStockHolding *stock3 = [[BNRForeignStockHolding alloc] init];
  
          stock1.purchaseSharePrice = 2.30;
          stock1.currentSharePrice = 4.50;
          stock1.numberOfShares = 40;
          stock1.symbol = @"XYZ";
  
          stock2.purchaseSharePrice = 12.19;
          stock2.currentSharePrice = 10.56;
          stock2.numberOfShares = 90;
          stock2.symbol = @"ABC";
  
          stock3.purchaseSharePrice = 45.10;
          stock3.currentSharePrice = 49.51;
          stock3.numberOfShares = 210;
          stock3.conversionRate = 0.94;
          stock3.symbol = @"LMN";
  
  
          NSMutableArray *mutable = [NSMutableArray array];
          [mutable addObject:stock1];
          [mutable addObject:stock2];
          [mutable addObject:stock3];
  
          BNRPortfolio *portfolio = [[BNRPortfolio alloc] init];
          portfolio.holdings = [mutable copy];
  
          float totalAmount = [portfolio totalValue];
  
          NSLog(@"total amount is %f",totalAmount);
  
  
  //        for (BNRStockHolding *n in mutable)
  //        {
  //            NSLog(@"%f",[n costInDollars]);
  //            NSLog(@"%f", [n valueInDollars]);
  //        }
  
  
  /*
  
          for (int i = 0; i &lt; [mutable count]; i++ )
          {
              NSLog(@" %d 's costInDollars = %.1f",i,[mutable[i] costInDollars]);
              NSLog(@" %d 's valueInDollars = %.1f",i,[mutable[i] valueInDollars]);
  
          }
  
   */
         BNRStockHolding *stock4 = [[BNRStockHolding alloc] init];
  
          stock4.purchaseSharePrice = 42.10;
          stock4.currentSharePrice = 22.51;
          stock4.numberOfShares = 230;
          stock4.symbol = @"LMN";
  
  
          [portfolio addStock:stock4];
  
          NSLog(@"count portfoio %ld",[portfolio.holdings count]);
  
      }
      return 0;
  }
  </code></pre>