Use of Undeclared Identifier "p"


#1

#import <Foundation/Foundation.h>

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

@autoreleasepool {
    @autoreleasepool {
        //Create a mutable array object,store it's address in items variable
        NSMutableArray *items = [[NSMutableArray alloc] init];
        
        //Send message to addObjec:to the NSMutable Array pointed to
        // By the variable items,passing  a string each time.
        [items addObject:@"One"];
        [items addObject:@"Two"];
        [items addObject:@"three"];
        
        //Send another message,insertObject:at index:'to that same array object
        [items insertObject:@"Zero" atIndex:0];
        
        //For every item in the array as determined by sending count to items
        for (int i =0; i<[items count];i++) {
            //We get the ith object from the array and pass it as an argument to
            
            //NSLog, which implicitly sends the description message to that object
            NSLog(@"%@",[items objectAtIndex:i]);
        }
        BNRItem *p = [[BNRItem alloc] init];
        //This creates a new NSString,"Read Sofaa and gives it to the BNRItem
        [p setItemName:@"Red Sofa"];                                                                 undeclared Identifier "p"
        //This creates a NSString,"A1B2C" and gives it to The BNRItem                 
        [p setSeriallNumber:@"A1B2C"];                                                           undeclared Identifier "p"
        //We Need To send the value100 to be used  as the caleInDollarsof this BNRItem
        [p setValueInDollars:100];                                                                          undeclared Identifier "p"
        
        //Remmeber, an NSSlog with %@ as the tokken will print the description of the corresponding argument
        NSLog(@"%@",p);                           undeclared Identifier "p"
        
        items = nil;      

import “BNRItem.h” Unknown type name Import

@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

    }
    return 0;
   
            
}
return 0;

}
I have not clue how to fix this. I have created new projects from scratch. I have saved it in a word processor and copied and pasted.I have rewritten the code several times. I have checked the forum for it. There is a forum that has a similar problem. I used that and try the new project. still no luck. If any one could help I would appreciated it.


#2

There are a lot of typos and the code looks to be in the wrong order. Try checking your code against the full solution set, which is located here: http://www.bignerdranch.com/solutions/iOSProgramming3ed.zip


#3

Thanks,I should have checked those folders.