ZGCPortfolio.h - declared new method
ZGCPortfolio.m - implemented method
- (NSArray *)topThreeHoldings
{
NSSortDescriptor *voh = [NSSortDescriptor sortDescriptorWithKey:@"valueInDollars" ascending:NO];
[_holdings sortUsingDescriptors:@[voh]];
return @[_holdings[0], _holdings[1], _holdings[2]]; // return NSArray of top three items (by index after sorting)
}
main.m
[color=#0000FF]OUTPUT*
2014-10-31 17:55:35.703 ObjC_Classes_ZGCPortfolio_Stocks_Challenge[3606:116486] My Holdings: (
“You paid $92.00USD for 40 shares of APPL, now valued at $180.00USD”,
“You paid $1097.10USD for 90 shares of BNNE, now valued at $1400.40USD”,
“You paid $112.50USD for 10 shares of CHPN, now valued at $225.00USD”,
“You paid $37.50USD for 10 shares of UKLN, now valued at $150.00USD”
)
2014-10-31 17:55:35.703 ObjC_Classes_ZGCPortfolio_Stocks_Challenge[3606:116486]
**** Your Portfolio’s total worth is valued at $1690.40USD ****
2014-10-31 17:55:35.704 ObjC_Classes_ZGCPortfolio_Stocks_Challenge[3606:116486] Top 3 Holdings: (
“You paid $1097.10USD for 90 shares of BNNE, now valued at $1400.40USD”,
“You paid $92.00USD for 40 shares of APPL, now valued at $180.00USD”,
“You paid $15.00USD for 10 shares of UKLN, now valued at $60.00USD”
)
2014-10-31 17:55:35.704 ObjC_Classes_ZGCPortfolio_Stocks_Challenge[3606:116486] Removing an asset…
2014-10-31 17:55:38.708 ObjC_Classes_ZGCPortfolio_Stocks_Challenge[3606:116486]
**** Your Portfolio’s total worth is valued at $290.00USD ****[/color]