Challenge : Solution


#1

#import <Foundation/Foundation.h>
#import “Person.h”
#import “StockingHolding.h”

int main(int argc, const char * argv[])
{

@autoreleasepool {
    
    // insert code here...
    
    NSMutableArray *array = [[NSMutableArray alloc] init];
    StockingHolding * stHolding = [[StockingHolding alloc] init];
    StockingHolding * stHolding2 = [[StockingHolding alloc] init];
    StockingHolding * stHolding3 = [[StockingHolding alloc] init];
    
    
    
    [stHolding setPurchaseSharePrice:2.30];
    [stHolding setCurrentSharePrice:4.50];
    [stHolding  setNumberOfShares:40];
    [stHolding costInDollars];
    [stHolding valueInDollars];
    
    [stHolding2 setPurchaseSharePrice:12.19];
    [stHolding2 setCurrentSharePrice:10.56];
    [stHolding2 setNumberOfShares:90];
    [stHolding2 costInDollars];
    [stHolding2 valueInDollars];
    
    [stHolding3 setPurchaseSharePrice:45.10];
    [stHolding3 setCurrentSharePrice:49.51];
    [stHolding3 setNumberOfShares:210];
    [stHolding3 costInDollars];
    [stHolding3 valueInDollars];
    
    
    
    
    
    
    [array addObject:stHolding];
    [array addObject:stHolding2];
    [array addObject:stHolding3];
    
    for (int i = 0; i <= 2; i++) {
        
   
    NSLog(@"%.2f  %.2f", [[array objectAtIndex:i] costInDollars], [[array objectAtIndex:i] valueInDollars]);
    
    
    }

// Destroy the array instance by setting it to nil, which will actually set the Memory free .:slight_smile: you will learn that in ARC…
array = nil,
}
return 0;
}


#2

Nice. Well done!

In future though, I recommend when ever you post code - put it in the tags as this will help users to easily read your code and assist.