title: Saving my array using NSUserDefaults
body: <p>I am having trouble with <code>NSUserDefaults</code>.  Please bear with me as it is my first time implementing it.</p>
  
  <p>The data I am trying to store to my phone is an array of objects for my <code>e-commerce</code> app's shopping cart, the same array that will load my cart's <code>table view</code> to display all the items added to the cart.  </p>
  
  <p>There are 2 different kinds of objects in the array that have different properties (<code>NSStrings</code> and <code>NSNumbers</code>: product name, size, price, etc.).  Someone suggested to me that perhaps there are too many properties in my array to put into the plist and that's why nothing is saving.</p>
  
  <p>Here is my code.  I am using a <code>singleton</code> method and have inserted this code into my <code>singleton</code> class.</p>
  
  <pre><code>- (void)save
  {  
      NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];  
      [userDefaults setObject:self.cartArray forKey:@"tableViewCartData"];
      [userDefaults synchronize];
      NSURL *plistURL = [[self documentsDirectory]URLByAppendingPathComponent:@"cartItems.plist"];
      [self.cartArray writeToURL:plistURL atomically:YES];
  }
  
  -(void)load
  {
      NSURL *plistURL = [[self documentsDirectory]URLByAppendingPathComponent:@"cartItems.plist"];
  
      self.cartArray = [NSMutableArray arrayWithContentsOfURL:plistURL];
      if (self.cartArray == nil)
      {
          self.cartArray = [NSMutableArray new];
      }
  }
  
  -(NSURL *)documentsDirectory
  {   
      NSFileManager *fileManager = [NSFileManager defaultManager];
      NSURL *url = [fileManager URLsForDirectory:NSDocumentDirectory inDomains:NSUserDomainMask].firstObject;
      return url;
  }
  </code></pre>
  
  <p>I can see in my Documents Directory that the plist gets created.  But there's nothing in there.</p>
  
  <p><strong>Edit</strong></p>
  
  <p>I just noticed this in my log:</p>
  
  <blockquote>
    <p>CityBicycleCompany[4239:249463] Property list invalid for format: 200
    (property lists cannot contain objects of type 'CFType') 2014-12-07
    20:52:10.037 CityBicycleCompany[4239:249463] Attempt to set a
    non-property-list object (
        "" ) as an NSUserDefaults/CFPreferences value for key tableViewCartData</p>
  </blockquote>
  
  <p>I'm not sure what it means.  What's a CFType?</p>
  
  <p><strong>Edit 2</strong></p>
  
  <p>Here is the po of <code>self.cartArray</code> at the moment (added one object to "cart").  ChosenAccessory is the custom <code>object</code> I added to the cart.</p>
  
  <pre><code>&lt;__NSArrayM 0x79788380&gt;( &lt;ChosenAccessory: 0x796d1f80&gt; )
  </code></pre>