Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

idelovski

macrumors regular
Original poster
Sep 11, 2008
235
0
I am reading Cocoa Design Patterns and I like it so far, but on page 141 I found the first thing that I think is wrong and I would not give it a second thought if there wasn't the same thing on page 143 in the method -mutableCopyWithZone: and now I'm not sure if it's wrong at all or if I'm missing something.

Errata for the book is missing in action and gives me: "The journal that this archive was targeting has been deleted. Please update your configuration."

Code:
- (id)copyWithZone:(NSZone *)aZone
{
   id   result = [[[self class] allocWithZone:aZone]
         initWithWord:[self word] clue:[self clue]];

   [[result puzzleSpecificAttributes] addEntriesFromDictionary:
         [self puzzleSpecificAttributes]];

   return self;   // THIS!
}

Returning self is wrong?

Yet, that is the first issue I found with this book. Everything before page 141 was so perfect, and now they made the same mistake twice (probably due to copy/paste editing) and of all places in the chapter about copying! ;)
 
That is definitely wrong. If you want to reassure yourself, run the static analyzer on that code.
 
Thanks,

unfortunately they don't give a full project for this chapter, but I can put someting similar into one of my own projects and test it there.
 
Thank you for the correction.

Thank you for the correction. The sample is in fact wrong. The method should return result. I will update the errata page for the book as soon as I figure out why it is broken.
 
Thank YOU for the book.

And if I may take the opportunity, does Cocoa Programming Developer's Handbook have anything to do with Cocoa Programming? Description on Amazon says "2nd edition" for this book by David Chisnall.

If it hasn't, is there any chance for the 2nd edition of original Cocoa Programming book?
 
As an Amazon Associate, MacRumors earns a commission from qualifying purchases made through links in this post.
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.