Help! I need hint to get sum working


EDIT: I came to A solution, but I am afraid it is not winning beauty contests…
Still interested in answers to my questions

I got the Portfolio challenge working to and up the list of 10 stock items, but I can’t get the sum method (shown in Employees example code, there: valueOfAssets:) working. I need that to get the total value of the Portfolio.
I really want to find the solution myself, but I really need some help. May I please ask some questions without posting my code, because, again, I want to find the solution myself.


  • I did not make Portfolio and Stockholding inherit from each other, but both subclasses of NSObject. Is that correct?
    (I did not forget to import in each other, and in main.m);

  • I suppose that I don’t need the method ‘AddAssetsObject’, as shown in the Employees example. I thought it is redundant in the Portfolio challenge. Am I wrong? Do I need it to get the sum-method working?

  • I created only one array, NSMutableArray *portfolio. One solution I think of: maybe I need a second array.

Your comments will be appreciated…

  1. Yes, that is correct. They should both be subclasses of NSObject.
  2. You will need some sort of method like addStockHolding() because you need a way to get the stock objects into the portfolio object.
  3. You should be able to complete this challenge with only the one array.

Chapter 19’s Asset class should give you everything you need to solve this challenge. Keep looking at the provided code in the chapter. You’ll get it!

One hint: Portfolio should have two methods. One will add objects to the portfolio (which is represented as an NSMutable array. The other will return the value of the portfolio.