Problem with challenge


Can someone please tell me what I’m doing wrong. I don’t appear to have any syntax errors but I’m getting 3 obscure error messages when I try to build stating:

'Apple Mach-O Linker (id) Error "_OBJC_CLASS_$_ForeignStockHolding", referenced from:'
And then a 4th error stating:

Here are my Portfolio and main files.


[code]#import <Foundation/Foundation.h>

#import “StockHolding.h”

@interface Portfolio : StockHolding

@property (strong) NSMutableArray *holdings;

-(void)addStockObject:(StockHolding *)stock;



[code]#import “Portfolio.h”
#import “StockHolding.h”

@implementation Portfolio

@synthesize holdings;

-(void)addStockObject:(StockHolding *)stock
// Add stock object to portfolio
[holdings addObject:stock];

// Sum up the value of the portfolio
float sum = 0;
for(StockHolding *stock in holdings){
sum += [stock valueInDollars];
return sum;



[code]#import <Foundation/Foundation.h>
#import “ForeignStockHolding.h”
#import “Portfolio.h”

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

@autoreleasepool {
    Portfolio *myPortfolio = [[Portfolio alloc] init];
    ForeignStockHolding *firstStock = [[ForeignStockHolding alloc] init];
    ForeignStockHolding *secondStock = [[ForeignStockHolding alloc] init];
    ForeignStockHolding *thirdStock = [[ForeignStockHolding alloc] init];
    StockHolding *fourthStock = [[StockHolding alloc] init];
    // Set conversion rates
    [firstStock setConversionRate:1.2];
    [secondStock setConversionRate:1.2];
    [thirdStock setConversionRate:1.2];
    // Set share info
    [firstStock setPurchaseSharePrice:1.10];
    [firstStock setNumberOfShares:10];
    [firstStock setCurrentSharePrice:1.30];
    [secondStock setPurchaseSharePrice:1.23 ];
    [secondStock setNumberOfShares:11];
    [secondStock setCurrentSharePrice:2.30];
    [thirdStock setPurchaseSharePrice:3.10];
    [thirdStock setNumberOfShares:15];
    [thirdStock setCurrentSharePrice:6.40];
    [fourthStock setPurchaseSharePrice:1.90];
    [fourthStock setNumberOfShares:50];
    [fourthStock setCurrentSharePrice:7.00];
    [myPortfolio addStockObject:firstStock];
    [myPortfolio addStockObject:secondStock];
    [myPortfolio addStockObject:thirdStock];
    [myPortfolio addStockObject:fourthStock];
    NSLog(@"The value of the portfolio is $%.2f",[myPortfolio currentValue]);
return 0;



For some reason, your StockHolding.m file is not being compiled into your program. Do you have a StockHolding.m file?


Yes, this is the contents of StockHolding.m

[code]#import “StockHolding.h”

@implementation StockHolding

@synthesize purchaseSharePrice;
@synthesize currentSharePrice;
@synthesize numberOfShares;

return [self purchaseSharePrice] * [self numberOfShares];

return [self currentSharePrice] * [self numberOfShares];



Try deleting it from the project (Just the reference, not the file) and re-add it. (Or you can go to the Compile Source Build Phase, and make sure StockHolding.m is listed.)