title: Sorting data by multiple key values
body: <p>I have a basic list app with two entities <code>Folder</code> and <code>Item</code> with a to many relationship, the folder subclass has a function called <code>itemsArray()</code> which returns the <strong>Items</strong> in a sorted array by <code>creationDate</code> which are displayed <code>UITableView</code>. </p>
  
  <p><code>Item</code> has two properties called <code>date</code> of type <code>NSDate</code> and another of type <code>bool</code> called <code>completed</code>. I have created a function where I can mark the cell item object as completed which changes the cell text color to grey.</p>
  
  <p>Is there a way I can also sort it by its completed value ? For e.g the <code>completed</code> value of true or false should separate all the completed items and then also sort it by the <code>creationDate</code>.</p>
  
  <p>The end result should be where the completed items are at the bottom of the <code>UITableView</code> and in order of date as well as the non completed items are in order of date. As if completion is higher priority than the date but still orders by creationDate </p>
  
  <p>Heres my current function with sort descriptor to return an array; </p>
  
  <pre><code>func itemsArray() -&gt; [Item] {
      let sortDescriptor = NSSortDescriptor(key: "creationDate", ascending: true)
      return checklist.sortedArrayUsingDescriptors([sortDescriptor]) as! [Item]
  }
  </code></pre>
  
  <p>PS: I tried some work arounds such as when marking as completed updating the date so it is at the bottom. This separates the completed items with the non completed. But when unmarking the item it remains at the bottom also this isn't a good long term solution as I may want to change the sorting to alphabetical order and completion. </p>