title: Core Data array
body: <p>I am using the code below to fetch the objects in an array. In my program, I have an array displayed in a tableview and when a cell is tapped, it leads to another array displayed in a tableview. The user can add cells in both of these tableviews. What is happening is that when I create new rows in my second tableview, go back, and tap the same cell that got me there, I notice that the objects I created are not there (they were reassigned to another cell). I believe that the problem lies in the line: <code>routines = results</code>. What I think is happening, is that when I tap back in my second view, the line <code>routines = results</code> is called again, and because <code>results</code> is by nature unordered, it messes up the order of my previously established <code>routines</code> array.</p>
  
  <pre><code>var routines = [NSManagedObject]()
  
  override func viewWillAppear(animated: Bool) {
  
      self.navigationItem.leftBarButtonItem = self.editButtonItem()
  
      let appDelegate = UIApplication.sharedApplication().delegate as! AppDelegate
      let managedContext = appDelegate.managedObjectContext!
  
      let fetchRequest = NSFetchRequest(entityName: "Routine")
  
      var error: NSError?
  
      let fetchedResults = managedContext.executeFetchRequest(fetchRequest, error: &amp;error) as! [NSManagedObject]?
  
      if let results = fetchedResults {
          routines = results
      } else {
          println("Could not fetch \(error), \(error!.userInfo)")
      }
  }
  </code></pre>