My solution to the challenge


#1

My first post to this board.

Portfolio.h

//
//  Portfolio.h
//  Stocks
//
//  Created by John Shea on 1/6/12.
//  Copyright (c) 2012 __MyCompanyName__. All rights reserved.
//

#import <Foundation/Foundation.h>
#import "StockHolding.h"
#import "ForeignStockHolding.h"

@interface Portfolio : StockHolding
{
    NSMutableArray *portfolioList;
    
}
-(void)addStockHolding:(StockHolding *)p;
-(float)currentValue;

@end

Portfolio.m

//
//  Portfolio.m
//  Stocks
//
//  Created by John Shea on 1/6/12.
//  Copyright (c) 2012 __MyCompanyName__. All rights reserved.
//

#import "Portfolio.h"

@implementation Portfolio

- (void)addStockHolding:(StockHolding *)p
{
    //is portfolio nil
    if (!portfolioList) {
        portfolioList = [[NSMutableArray alloc] init];
        
    }
    [portfolioList addObject:p];
    
}

- (float)currentValue {
    float value = 0;
    //iterate through stocks
    for (Portfolio *stock in portfolioList) {
        value += [stock valueInDollars];
    }

    return value;
}
@end