P.51 Strange green failing message


I am stuck just by following instructions…
On page 51 I am supposed to override an init method to call a designated one.

In the BNRItem.m file, the lines of code beneath is ment to be inserted somewhere, but not specified, so i assume anywhere within @implementation@end.

  • (id)init
    return [self initWithItemName:@“Item"

On page 52, I am supposed to insert NSLog(@"%@", p); and get:

item (): Worth 0, recorded on date and time +0000 Red Sofa (A1B2C): Worth 100, recorded on date and time +0000


I get a green fail message on the return [self initWi…] line saying Thread 1: Signal SIGABRT

I can build and run but I get the following:

2012-09-06 10:32:17.358 RandomPossessions[10655:403] Zero 2012-09-06 10:32:17.408 RandomPossessions[10655:403] one 2012-09-06 10:32:17.411 RandomPossessions[10655:403] two 2012-09-06 10:32:17.413 RandomPossessions[10655:403] three 2012-09-06 10:32:17.414 RandomPossessions[10655:403] -[BNRItem initWithItemName:valueInDollars:serialNumber:]: unrecognized selector sent to instance 0x103c001f0 2012-09-06 10:32:17.415 RandomPossessions[10655:403] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[BNRItem initWithItemName:valueInDollars:serialNumber:]: unrecognized selector sent to instance 0x103c001f0' *** First throw call stack: ( 0 CoreFoundation 0x00007fff8acfcf56 __exceptionPreprocess + 198 1 libobjc.A.dylib 0x00007fff8d8ddd5e objc_exception_throw + 43 2 CoreFoundation 0x00007fff8ad891be -[NSObject doesNotRecognizeSelector:] + 190 3 CoreFoundation 0x00007fff8ace9e23 ___forwarding___ + 371 4 CoreFoundation 0x00007fff8ace9c38 _CF_forwarding_prep_0 + 232 5 RandomPossessions 0x0000000100001921 -[BNRItem init] + 81 6 RandomPossessions 0x0000000100001424 main + 420 7 RandomPossessions 0x0000000100001274 start + 52 8 ??? 0x0000000000000001 0x0 + 1 ) terminate called throwing an exception(lldb)


#import "BNRItem.h"

@implementation BNRItem 

-(id)initWithItemName:(NSString *)name
serialNumber:(NSString *)sNumber
//call the superclasses designated initializer
    self =[super init];
    // did the superclass's designated initializer succeed?

//give the instance variables initial values

    if(self) {
    [self setItemName:name];
     [self setSerialNumber:sNumber];
    [self setValueInDollars:value];
    dateCreated = [[NSDate alloc]init];
   // return the address of the newly initiated object
    return self;

-(NSString *)description
    NSString *descriptionString =
    [[NSString alloc] initWithFormat:@"%@ (%@):Worth $%d, recorded on%@",
    return descriptionString;

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


-(NSString *)itemName;
    return itemName;

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

-(NSString *) serialNumber;
    return serialNumber;

    valueInDollars = i;

    return valueInDollars;

-(NSDate *) dateCreated
    return dateCreated;

- (id)init
    return [self initWithItemName:@"Item" //This is where I get the weird green fail message.



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

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

    @autoreleasepool {
       //Create a mutable array object, store its address in items variable by the variable items, passing a string each time
        NSMutableArray *items = [[NSMutableArray alloc] init];
        [items addObject:@"one"];
        [items addObject:@"two"];
        [items addObject:@"three"];
        //send another message, insertObject:atIndex, 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];
        NSLog(@"%@", p);
        //this reates a new NSString, "red Sofa" and gives it to the BNRitem
        [p setItemName:@"Red Sofa"];
        //this creates a new NSSString, "A1B2C" and gives it to the BNRItem
        [p setSerialNumber:@"A1B2C"];
        //We send the value 100 to be used as the valueInDollars of this BNRItem
        [p setValueInDollars:100];
        //Remember, an NSLog with %@ as the token will print the description of the correspondning argument
        //Destroy the array pointed to by items
        items = nil;
    return 0;