title: NSKeyedArchiver and NSKeyedUnarchiver with NSMutableArray
body: <p>I'm hoping this isn't something to do with the fact that I'm using a Mutable array here, but this one is baffling me so it wouldn't surprise me if that were the case.</p>
  
  <p>BACKGROUND:</p>
  
  <p>I have made a small database which is essentially an NSMutableArray containing custom objects, which we can call recordObjects.  I set up the array:</p>
  
  <pre><code>database = [[NSMutableArray alloc] init];
  </code></pre>
  
  <p>and my custom object, called "recordObject" contains the following variables and inits:</p>
  
  <pre><code>NSString *name;
  int       anInt;
  Bool      aBool;
  </code></pre>
  
  <p>I also synthesized methods so I can make calls like:</p>
  
  <pre><code>aString = [[database objectAtIndex:someIndex] name];
  </code></pre>
  
  <p>And added methods to my controller class to add, remove, and select the individual records for display.  So far everything works correctly and exactly as expected.</p>
  
  <p>Next, I've set up my recordObject class (subclass of NSObject) to use the NSCoder (by including  in the @interface directive, and have added the following custom encoder and decoder methods in the implementation file:</p>
  
  <pre><code>-(void) encodeWithCoder: (NSCoder *) encoder {
      [encoder encodeObject: name  forKey: @"recordName"];
      [encoder encodeInt:    anInt forKey: @"recordInteger"];
      [encoder encodeBool:   aBool forKey: @"recordBool"];
  }
  
  -(id) initWithCoder: (NSCoder *) decoder {
      name    = [decoder decodeObjectForKey: @"recordName"];
      anInt   = [decoder decodeIntForKey:    @"recordInteger"];
      aBool   = [decoder decodeBoolForKey:   @"recordBool"];
  }
  </code></pre>
  
  <p>In order to write the file, I have used the following:</p>
  
  <pre><code>[NSKeyedArchiver archiveRootObject:database toFile:myPath];
  </code></pre>
  
  <p>When I run the program, everything APPEARS to work correctly.  The encoder method is called for each of the records in the array and the file is written to disk.  Opening the file with TextEdit shows that the data is there (though mostly unintelligible to me.)</p>
  
  <p>THE PROBLEM:</p>
  
  <p>Here's where I run into a snag.</p>
  
  <p>I added the following code to LOAD the file into my database array:</p>
  
  <pre><code>database = [NSKeyedUnarchiver unarchiveObjectWithFile:myPath];
  </code></pre>
  
  <p>When I run the program again, this time Loading the database, it APPEARS to work correctly.  My first test was to use the NSMutableArray count method:</p>
  
  <pre><code>x = [database count];
  </code></pre>
  
  <p>The result was that X is filled with the correct number of records in the file.  If there were 5 records when I saved the database, X is set to 5 after loading the database on the next execution of the program.</p>
  
  <p>Now, here's the big problem:</p>
  
  <p>The program crashes if I try to use ANY of my accessor methods.  For example, if I try to use the following after loading the database:</p>
  
  <pre><code>aString = [[database objectAtIndex:someIndex] name];
  </code></pre>
  
  <p>the program crashes and returns the following error in the console:</p>
  
  <pre><code>Program received signal:  “EXC_BAD_ACCESS”.
  sharedlibrary apply-load-rules all
  </code></pre>
  
  <p>My interpretation is that the data is not being loaded and initialized into the database array correctly for some reason, but for the life of me I can't figure out where I've gone wrong here.</p>
  
  <p>As a side note, everything I've implemented came from Stephen G. Kochan's book "Programming in Objective-C"</p>
  
  <p>Any ideas would be greatly appreciated!</p>