What am I doing wrong here?


#1

I’m working on the Gold Challenge, and this is my BNRContainer.h file:

[quote]#import <Foundation/Foundation.h>
#import “BNRItem.h”

@interface BNRContainer : BNRItem
{
NSMutableArray *array;
}

@property (atomic, strong) NSMutableArray *array;

-(id)initWithItemName:(NSString *)name
valueInDollars:(int)value;

@end[/quote]

But when I try to run the program, I get a message in this file that says, “cannot find interface declaration of BNRItem, superclass of BNRContainer.”

But . . . isn’t the declaration right there?

What gives?


#2

Is the BNRItem.h included in the project? Having the #import “BNRItem.h” is not sufficient.

Also make sure that BNRItem.h provides the class declaration for BNRItem.


#3

Yes, BNRItem.h is included in the project (along with BNRItem.m). Here’s the code for BNRItem.h.

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

@interface BNRItem : NSObject
{
NSString *itemName;
NSString *serialNumber;
int valueInDollars;
NSDate *dateCreated;
}

@property (atomic, strong) NSString *itemName;
@property (atomic, strong) NSString *serialNumber;
@property (atomic) int valueInDollars;
@property (atomic, strong) NSDate *dateCreated;

-(id)initWithItemName:(NSString *)name
valueInDollars:(int)value
serialNumber:(NSString *)sNumber;

+(id)randomItem;

@end[/code]

And while I’m at it–if I try to use

-(id)initWithItemName:(NSString *)name valueInDollars:(int)value serialNumber:(NSString *)sNumber;

which is declared in BNRItem, to send a message to an instance of BNRContainer, I get an error message–I can only use it if I declare it in BNRContainer as well. But if BNRContainer is a subclass of BNRItem, it should inherit all the methods, shouldn’t it?


#4

[quote=“derfner”] …

[quote]#import <Foundation/Foundation.h>
#import “BNRItem.h”

@interface BNRContainer : BNRItem
{
NSMutableArray *array;
}

@property (atomic, strong) NSMutableArray *array;

[color=#FF0000]-(id)initWithItemName:(NSString *)name
valueInDollars:(int)value;[/color]

@end[/quote]…
[/quote]

What is the method in [color=#FF0000]red[/color] for? Looks like you are declaring a new method in BNRContainer itself, for which you should provide a definition.

If you are still stuck, please post your source files (*.h and *.m).


#5

I couldn’t figure this out, so I scrapped it and started over. Thirteen times. But I finally got it. Whew. I hope the rest of the Gold Challenges in the book aren’t this difficult…