Strange problem - probably my fault!


#1

Hi guys,

I am getting a strange error once I get to page 290 of the 3rd Edition, at the bit where you implement the changes to removeItem: in BNRItemStore.m. It tells me that 'no visible interface for ‘BNRItem’ declares the selector ‘imageKey’. I have checked my import statements at the top of BNRItemStore.m, which are:

#import “BNRItem.h”
#import “BNRImageStore.h”
#import “BNRItemStore.h”

The source code for the method itself:

  • (void) removeItem:(BNRItem *)p
    {
    NSString *key = [p imageKey]; // Error on this line

    [[BNRImageStore sharedStore] deleteImageForKey:key];

    [allItems removeObjectIdenticalTo:p];
    }

I have also checked my property declarations in BNRItem.h, which are:

@property (nonatomic, copy) NSString *itemName;
@property (nonatomic, copy) NSString *itemName2;
@property (nonatomic, copy) NSString *serialNumber;
@property (nonatomic) int valueInDollars;
@property (nonatomic, readonly, strong) NSDate *dateCreated;
@property (nonatomic, copy) NSString *imageKey;

And the synthesizers:

@synthesize container;
@synthesize containedItem;
@synthesize itemName, serialNumber, dateCreated, valueInDollars, itemName2;
@synthesize imageKey;

Notice, I’ve also created another property called itemName2 just for testing - and I can’t seem to access this from BNRItemStore.m either. The strange thing is, when I try to access these same properties from inside DetailViewController.m, it works perfectly fine. Is there something really obvious I’m missing here?! I’m sure
I’ve done something wrong but I don’t know what.

Many thanks for your help

Nick


#2

Did you import “BNRItem.h” into the file with the error?


#3

Yes I did, but it still gave the same error. I spent several hours on it but still couldn’t see what the problem was. Eventually I resorted to copying the BNRItem.h, BNRItem.m, BNRItemStore.h and BNRItemStore.m files from the example zip and dropped them directly into my project directory and did a rebuild - but it still gave the error on the same line! Bizarre.

So in the end I just abandoned it and moved onto the next chapter, with a fresh copy of the project from the example zip, and it works fine now.

Thanks for your help anyway,

Nick


#4

In Xcode, Command+1 to open the Project Navigator. Right click on BNRItemStore (.h/.m doesn’t matter), and click “Show in Finder”. Now look within that directory (might be its parent directory or a subdirectory, depending on how your files are organized) for BNRItem.h. Open this file and see if you see the property for imageKey. Is is there?

If not, the BNRItem in your project is actually not the same as the BNRItem in your directory (which the compiler is loading). If this is the problem, go back into Xcode and right click on BNRItem.h, and click “Show in Finder”. This BNRItem.h/.m combo should be the one that you are editing in your project. You’ll want to remove the old BNRItems that you found in the first paragraph of this post from the directory, remove the references to BNRItem in your project, and then re-copy the correct BNRItem back in. Make sure you check the 2 checkboxes to copy the file into the project as well as to add it to the target.