title: How do I sort Swift objects by multiple criteria
body: <p>I have a list of Swift objects that I'd like to get sorted by multiple criteria. The objects in the list are of type <code>DateRange</code>:</p>
  
  <pre><code>class DateRange {
      var from: NSDate?
      var to: NSDate?
  }
  </code></pre>
  
  <p>The list contains many of these objects where some <code>from</code> or <code>to</code> fields are nil. I want to have this list sorted by:</p>
  
  <ol>
  <li>First all objects that have dates</li>
  <li>Then objects that have at least one date (either <code>from</code> or <code>to</code>)</li>
  <li>And at the very end objects without any</li>
  </ol>
  
  <p>The dates itself don't matter, just their existence. In Ruby I could do this (if the date is <code>nil</code> I set it to a very low date):</p>
  
  <pre><code>date_ranges.sort { |a, b|
    [fix_nil(a.from), fix_nil(a.to)] &lt;=&gt; [fix_nil(b.from), fix_nil(b.to)]
  }.reverse
  
  def fix_nil(val)
    val.nil? ? Date.new(0) : val
  end
  </code></pre>
  
  <p>What's the best way to do this with Swift? Thanks in advance.</p>