Chapter2 BNRItem Parsing Error


#1

First of all, thank you for a GREAT book! I just got the book on Friday and I have been reading and working through the code examples. This forum has been especially helpful as a debugging tool for me since I am learning new coding skills.

I am running Xcode 4.3.2 on iOS SDK 5.1. I have tried to follow your example to the letter for creating the BNRItem .h and .m files. This seems to be a straightforward class but I am unable to parse/build the code. I get this parse issue on the line with “@implementation BNRItem” The error message is "Expected identifier or ‘(’ "

This is the .h file

#import <Foundation/Foundation.h>

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

- (void)setItemName:(NSString *)str;
- (NSString *)itemName;

- (void)setSerialNumber:(NSString *)str;
- (NSString *)serialNumber;

- (void)setValueInDollars:(int)i;
- (int)valueInDollars;

- (NSDate *)dateCreated;
@end

This is the .m file


#import "BNRItem.h"

@implementation BNRItem

- (void)setItemName:(NSString *)str
{
    itemName = str;
}

- (NSString *)itemName
{
    return itemName;
}

- (void)setSerialNumber:(NSString *)str 
{
    serialNumber = str;
}

- (NSString *)serialNumber
{
    return serialNumber;
}

- (void)setValueInDollars:(int)i
{
    valueInDollars = i;   
}

- (int)valueInDollars 
{
    return valueInDollars;
}

- (NSDate *)dateCreated
{
    return dateCreated;
}

@end

Any suggestions would be greatly appreciated. I am sure the problem is staring at me in the face, but I don’t see it.

Russ


#2

Hm. These two files compile just fine when I copy them in.

On a hunch, try opening the file RandomPossession-Prefix.pch. Is there anything in there but the following?

//
// Prefix header for all source files of the 'Test' target in the 'Test' project
//

#ifdef __OBJC__
    #import <Foundation/Foundation.h>
#endif

#3

Thank you for responding. No. There is nothing more in the specific file you mentioned.


#4

Weird. Have you tried creating a new project and copying in those two files? Have you tried removing those two files from the project and compiling it? There must be a stray character somewhere…


#5

Joe,

Thank you! Yep were right. I had to go back and recreate a project. I suspect the project I was using was not correctly created by myself.

Russ