title: Order array of string date ("yyyy-MM-dd HH:mm:ss.SSSSSS") by date
body: <p>I have an array of a custom structure called <code>TransactionValues</code> that has a <code>dateAdd</code> property with strings like <code>"2019-02-09 03:57:22.837371"</code>, <code>"2019-02-08 04:55:12.833307"</code> and <code>"2019-02-09 12:44:22.335671"</code>. I have a method where I'm sorting the array elements:</p>
  
  <pre><code>func sortByDate(array: [TransactionValues]) -&gt; [TransactionValues] {
      print(array)
      let dateFormatter = DateFormatter()
      dateFormatter.dateFormat = "yyyy-MM-dd HH:mm:ss"
      let sortedArray = array.sorted { dateFormatter.date(from: $0.dateAdd)! &lt; dateFormatter.date(from: $1.dateAdd)! }
      print(sortedArray)
      return sortedArray
  }
  </code></pre>
  
  <p>But it fails with error: </p>
  
  <blockquote>
    <p>Fatal error: Unexpectedly found nil while unwrapping an Optional value</p>
  </blockquote>
  
  <p><code>$0.dateAdd</code> and <code>$1.dateAdd</code> aren't nil.</p>
  
  <p>Any help will be appreciated.</p>