views:

173

answers:

1

I just upgraded to Xcode 3.2 and am using the Build and Analyze feature to check old code for errors.

While doing something I thought was innocuous, I get this error:

"Dead store: Value stored to 'newBook' during it's initialization is never read in SpellTest.m"

#define kSpellBookFilename @"TestBookSaver"

-(void)testBookLoadFromDisk;
{
    // restore object from disk
    SpellBook *newBook = [[[SpellBook alloc] init] autorelease];
    newBook = [NSKeyedUnarchiver unarchiveObjectWithFile:kSpellBookFilename];

    // show restored object
    NSLog(@"archived copy %@", newBook);
}

Am I initializing this object wrong or is this a false positive?

+3  A: 

It is a dead store. Why do you even initialize a new SpellBook object in the first code line when you just throw it away in the next line? Just remove the first line (and move the type declaration to the second one).

Ringding
DOH!!!! I knew that was true with native objects but I had somehow got it in my head that custom objects have to be alloc/inited first. I'm a Obj-C noob but that's just silly in retrospect. Thanks dude, I just went up a level.
willc2