Missing something obvious


#1

Below is my solution to the challenge. In main.h I am getting multiple errors when I call any of the methods that I defined in Portfolio class. I have checked everything I know of, and compared my solution with several of the others and for the life of me don’t know what I am missing, but it must be something obvious. The Portfolio h and m file both compile with no errors. In main I getting multiple results of [color=#FF0000] "No known class method for selector “addStock”, “costSum”, and valueSum[/color].

What am I doing wrong??

Thanks for the help!

//
// Portfolio.h
// Stocks
//
// Created by John Frost on 2/18/12.
// Copyright © 2012 MyCompanyName. All rights reserved.
//

#import <Foundation/Foundation.h>
#import “StockHolding.h”

@interface Portfolio : StockHolding
{
//Create Array
NSMutableArray *myPortfolio;

}
@property (strong) NSMutableArray *myPortfolio;

  • (void) addStock:(StockHolding *)d;
  • (float) costSum;
  • (float) valueSum;
    @end

//
// Portfolio.m
// Stocks
//
// Created by John Frost on 2/18/12.
// Copyright © 2012 MyCompanyName. All rights reserved.
//

#import “Portfolio.h”
#import “StockHolding.h”

@implementation Portfolio
@synthesize myPortfolio;

-(void)addStock: (StockHolding *)d
{
//Is portfolio nil?
if (!myPortfolio)
{ //Creat the Array
myPortfolio = [[NSMutableArray alloc] init];
}
[myPortfolio addObject:d];
}

-(float)costSum{
float cost = 0;
for (Portfolio *p in myPortfolio){
cost += [p costInDollars];
}
return cost;
}

-(float)valueSum{
int value = 0;
for (Portfolio *p in myPortfolio){
value += [p valueInDollars];
}
return value;
}

@end

//
// main.m
// Stocks
//
// Created by John Frost on 2/18/12.
// Copyright © 2012 MyCompanyName. All rights reserved.
//

#import <Foundation/Foundation.h>
#import “StockHolding.h”
#import “ForeignStockHolding.h”
#import “Portfolio.h”

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

@autoreleasepool {
    
    // Creat Six StockHolding Objects
    StockHolding *stock1 =[[StockHolding alloc]init];
    StockHolding *stock2 =[[StockHolding alloc]init];
    StockHolding *stock3 =[[StockHolding alloc]init];
    ForeignStockHolding *stock4 =[[ForeignStockHolding alloc]init];
    ForeignStockHolding *stock5 =[[ForeignStockHolding alloc]init];
    ForeignStockHolding *stock6 =[[ForeignStockHolding alloc]init];
    
    //Assign Values to the instance variables
    [stock1 setPurchaseSharePrice:2.30];
    [stock1 setCurrentSharePrice:4.50];
    [stock1 setNumberOfShares:40];
    [stock1 setStockId:1];
    
    
    [stock2 setPurchaseSharePrice:12.19];
    [stock2 setCurrentSharePrice:10.58];
    [stock2 setNumberOfShares:90];
    [stock2 setStockId:2];
    
    [stock3 setPurchaseSharePrice:45.10];
    [stock3 setCurrentSharePrice:49.51];
    [stock3 setNumberOfShares:210];
    [stock3 setStockId:3];
    
    [stock4 setPurchaseSharePrice:45.10];
    [stock4 setCurrentSharePrice:49.51];
    [stock4 setNumberOfShares:210];
    [stock4 setStockId:4];
    [stock4 setConversionRate:0.9];
    
    [stock5 setPurchaseSharePrice:2.30];
    [stock5 setCurrentSharePrice:4.50];
    [stock5 setNumberOfShares:40];
    [stock5 setStockId:5];
    [stock5 setConversionRate:0.9];
    
    [stock6 setPurchaseSharePrice:12.19];
    [stock6 setCurrentSharePrice:10.58];
    [stock6 setNumberOfShares:90];
    [stock6 setStockId:6];
    [stock6 setConversionRate:0.9];
    
    //create an Empty Array
    //NSMutableArray *stocklist = [[NSMutableArray alloc] init];
    
    //Add stocks to the Array
    [Portfolio addStock: stock1];
    [Portfolio addStock: stock2];
    [Portfolio addStock: stock3];
    [Portfolio addStock: stock4];              [color=#FF0000]Returns the error "No known class method for selector "addStock"[/color]
    [Portfolio addStock: stock5];
    [Portfolio addStock: stock6];
    
    //Print the Cost & Value of Each Stock
    //for (StockHolding *s in stocklist){
    // NSLog (@"%i shares of Stock%i were purchased for $%.2f per share for a total purchase price of $%.2f. Current ly Stock%i is selling for $%.2f per share and is now worth $%.2f",[s numberOfShares],[s stockId],[s purchaseSharePrice],[s costInDollars], [s stockId], [s currentSharePrice], [s valueInDollars]);
    //}
    
    NSLog (@"Portfolio Cost Basis is %.2f Current Value is %.2f",[Portfolio costSum],[Portfolio valueSum]);
           
    }
           return 0;

}


#2

You never created an instance of Portfolio:

Portfolio *p = [[Portfolio alloc] init];
Then add the stocks to that.


#3

Duh!!!
I knew it had to be something obvious!!
Thanks
1