Chapter 19 Challenge


Love the book… first time I’ve ever grasped this material… all because of you Mr. Hillegass.

However, while I get the concepts and even completed the challenge with the expected results, I’m getting a warning, that after many hours of investigation, I still can’t figure out. I’m happy my code works as I thought it would, but dissapointed I can’t figure out why the warning is thrown… My sanity would appreciate know why… can you help?

In my main.m

//Create a Portfolio
Portfolio *myOnlyPortfolio = [[Portfolio alloc] init];
[myOnlyPortfolio setPortfolioID:1];

    for (int i=0; i<10; i++)
        //let's create a stock object
        StockHolding *thisstock = [[StockHolding alloc] init];
        //let's give it some values
        [thisstock setNumberOfShares:i*100];
        [thisstock setPurchaseSharePrice:100-i];
        [thisstock setCurrentSharePrice:100+i];
        //now we add this stock to our stock array            
      [color=#0080FF] [myOnlyPortfolio addStockObject:thisstock];[/color]  [color=#00BF80][b]<== Warning "Incompatible pointer types sending 'StockHolding*_strong' to parameter of type 'Stockholding *'[/b][/color]
        int totalValOfStock = [myOnlyPortfolio valueOfStocks];
        NSLog(@"My total value is %d", totalValOfStock);            

I know the warning is referring back to my Portfolio Class

// Portfolio.h
// StockHolding


#import <Foundation/Foundation.h>
@class Stockholding;

@interface Portfolio : NSObject
int portfolioID;
NSMutableArray *stocks;

@property int portfolioID;

  • (void) addStockObject:(Stockholding *)s;
  • (unsigned int) valueOfStocks;

// Portfolio.m
// StockHolding

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

@implementation Portfolio
@synthesize portfolioID;
-(void) addStockObject:(Stockholding *)s
//is the array nil?
if (!stocks) {
stocks = [[NSMutableArray alloc] init];
[stocks addObject:s];

  • (unsigned int)valueOfStocks
    unsigned int sum=0;
    for (StockHolding *s in stocks) {
    sum+= [s valueInDollars];
    return sum;



The problem is your lowercase H. The method should be declared:

(And thanks a lot for the kind words. They really mean a lot to me.)


Additionally, the build probably didn’t catch the error at an earlier stage because in Portfolio.h you declared:

@class Stockholding;

Which of course should be:

@class StockHolding;