title: iPhone / Objective-C: NSMutableArray writeToFile won't write to file. Always returns NO
body: <p>I'm trying to serialize two <code>NSMutableArrays</code> of <code>NSObjects</code> that implement the <code>NSCoding</code> protocol.  However it works for one (<code>stacks</code>) and not the other (<code>cards</code>). I have the following block of code:</p>
  
  <pre><code>-(void) saveCards
  {
      NSArray* paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); 
      NSString* documentsDirectory = [paths objectAtIndex:0];
  
      NSString* cardsFile = [documentsDirectory stringByAppendingPathComponent:@"cards.state"];
      NSString* stacksFile = [documentsDirectory stringByAppendingPathComponent:@"stacks.state"];
      BOOL c = [rootStack.cards writeToFile:cardsFile atomically:YES];
      BOOL s = [rootStack.stacks writeToFile:stacksFile atomically:YES];
  }
  </code></pre>
  
  <p>I step through this method using the debugger, and after the last two lines of code run, I check the values of the two <code>BOOL</code>s. <code>BOOL c</code> is <code>NO</code> and <code>BOOL s</code> is <code>YES</code>. The <code>stacks</code> array is actually empty (which is probably why it works). The <code>cards</code> array has contents. Why is it that the array with contents is failing? I can't figure this out. I've looked through numerous threads on SOF, each of them say the problem is because the protection level of the files they were writing were preventing them from writing. This is not my problem, as I'm writing to the Documents folder. I've double and tripple checked that neither <code>rootStack.cards</code> nor <code>rootStack.stacks</code> is nil. And I've checked that cards does indeed have content.</p>
  
  <p>Here are the coder methods for my Notecard class (I added all the <code>if</code> statments as part of trying to solve this problem to make sure trying to encode nil values doesn't break something):</p>
  
  <pre><code>-(void) encodeWithCoder:(NSCoder *)encoder
  {
      if(text)
          [encoder encodeObject:text forKey:@"text"];
      if(backText)
          [encoder encodeObject:backText forKey:@"backText"];
      if(x)
          [encoder encodeObject:x forKey:@"x"];
      if(y)
          [encoder encodeObject:y forKey:@"y"];
      if(width)
          [encoder encodeObject:width forKey:@"width"];
      if(height)
          [encoder encodeObject:height forKey:@"height"];
      if(timeCreated)
          [encoder encodeObject:timeCreated forKey:@"timeCreated"];
      if(audioManagerTicket)
          [encoder encodeObject:audioManagerTicket forKey:@"audioManagerTicket"];
      if(backgroundColor)
          [encoder encodeObject:backgroundColor forKey:@"backgroundColor"];
  }
  
  -(id) initWithCoder:(NSCoder *)decoder
  {
      self = [super init];
      if(!self)
          return nil;
  
      self.text               = [decoder decodeObjectForKey:@"text"];
      self.backText           = [decoder decodeObjectForKey:@"backText"];
      self.x                  = [decoder decodeObjectForKey:@"x"];
      self.y                  = [decoder decodeObjectForKey:@"y"];
      self.width              = [decoder decodeObjectForKey:@"width"];
      self.height             = [decoder decodeObjectForKey:@"height"];
      self.timeCreated        = [decoder decodeObjectForKey:@"timeCreated"];
      self.audioManagerTicket = [decoder decodeObjectForKey:@"audioManagerTicket"];
      self.backgroundColor    = [decoder decodeObjectForKey:@"backgroundColor"];
  
      return self;
  }
  </code></pre>
  
  <p>each field is either an NSString, NSNumber, or UIColor.</p>
  
  <p>Thanks for any help</p>