title: Save own Class with NSCoder
body: <p>I'm trying to store some custom class/data to a file in my iPhone/iPad app.</p>
  
  <p>I have a Class RSHighscoreList</p>
  
  <pre><code>@interface RSHighscoreList : NSObject {
      NSMutableArray *list;
  }
  </code></pre>
  
  <p>which contains objects of RSHighscore in the list</p>
  
  <pre><code>@interface RSHighscore : NSObject {
      NSString *playerName;
      NSInteger points;
  }
  </code></pre>
  
  <p>When I try to store all to file</p>
  
  <pre><code>- (void)writeDataStore {
      RSDataStore *tmpStore = [[RSDataStore alloc] init];
      _tmpStore.highscorelist = self.highscorelist.list;
      NSMutableData *data = [[NSMutableData alloc] init];
      NSKeyedArchiver *archiver = [[NSKeyedArchiver alloc] initForWritingWithMutableData:data];
  
      [archiver encodeObject:tmpStore forKey:kDataKey];
      [archiver finishEncoding];
      [data writeToFile:[self dataFilePath] atomically:YES];
  
      [archiver release];
      [data release];
  }
  
  @interface RSDataStore : NSObject &lt;NSCoding, NSCopying&gt; {
      NSMutableArray *highscorelist; 
  }
  
  - (void)encodeWithCoder:(NSCoder *)encoder {
      [encoder encodeObject:highscorelist forKey:@"Highscorelist"];
  }
  </code></pre>
  
  <p>The app will crash with an error message</p>
  
  <blockquote><pre>-[RSHighscore encodeWithCoder:]: unrecognized selector sent to instance 0x573cc20
  *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[RSHighscore encodeWithCoder:]: unrecognized selector sent to instance 0x573cc20'</pre></blockquote>
  
  <p>I wonder why the error tells about RSHighscore, even if that is 'wrapped'. Does anyone have a good idea?</p>