title: Synchronise array stored in NSUserDefaults?
body: <p>I've just tried using an updated version of my app on an iPhone which has the version installed that is currently on the app store. I have added a few new features since the last update which seems to cause the app to crash.</p>
  
  <p>Basically, I added a new array that stores data for notes which was not present in previous versions and this is stored in NSUserDefaults (Not ideal, I know, but I would rather keep it this way for now)</p>
  
  <p>This is the code I have in my table view where the app crashes:</p>
  
  <pre><code>cell.notesLabel.text = (notes.objectAtIndex(indexPath.row)) as? String
  </code></pre>
  
  <p>The error just states - "Thread 1: breakpoint 1.1" as soon as the table view tab is tapped.</p>
  
  <p>I was discussing this with someone else and they suggested that I need to check for the existence of the array in the defaults and create and synchronise it if it is missing.</p>
  
  <p>I've only been programming for a few months so this doesn't mean a whole lot to me. But I assume I would just need do something like this:</p>
  
  <pre><code>if NSUserDefaults.standardUserDefaults().arrayForKey("notes") == nil {
    //Do something?
  }
  </code></pre>
  
  <p>I'm unsure about what he means by synchronise? Anyone have any suggestions?</p>
  
  <p>At the moment in <code>viewWillAppear()</code> I have this code:</p>
  
  <pre><code>    if var tempNames: NSArray = NSUserDefaults.standardUserDefaults().arrayForKey("names") {
          names = tempNames.mutableCopy() as NSMutableArray
      }
      if var tempDates: NSArray = NSUserDefaults.standardUserDefaults().arrayForKey("dates") {
          dates = tempDates.mutableCopy() as NSMutableArray
      }
      if var tempValues: NSArray = NSUserDefaults.standardUserDefaults().arrayForKey("values") {
          values = tempValues.mutableCopy() as NSMutableArray
      }
      if var tempImages: NSArray = NSUserDefaults.standardUserDefaults().arrayForKey("images") {
          images = tempImages.mutableCopy() as NSMutableArray
      }
      if var tempUnformatted: NSArray = NSUserDefaults.standardUserDefaults().arrayForKey("unformatted") {
          unformatted = tempUnformatted.mutableCopy() as NSMutableArray
      }
      if var tempNotes: NSArray = NSUserDefaults.standardUserDefaults().arrayForKey("notes") {
          notes = tempNotes.mutableCopy() as NSMutableArray
      }
  </code></pre>
  
  <p>EDIT:</p>
  
  <p>I tried changing my code to this, but I have the same issue:</p>
  
  <pre><code>    if NSUserDefaults.standardUserDefaults().arrayForKey("notes") != nil {
          var tempNotes: NSArray = NSUserDefaults.standardUserDefaults().arrayForKey("notes")!
          notes = tempNotes.mutableCopy() as NSMutableArray
      }
  </code></pre>