title: Sorting dictionary in Swift 3
body: <p>Trying to sort an NSMutableDictionary in Swift 3, code from Swift 2 doesn't work for me anymore (various errors).</p>
  
  <p>I am trying to use the following code to sort my dictionary by its values, which are floats:</p>
  
  <pre><code>var sortedDict = unsortedDict.allValues.sorted({ $0 &lt; $1 }).flatMap({ floatedlotterydictionary[$0] })
  </code></pre>
  
  <p>Essentially, I want this unsorted dictionary...</p>
  
  <pre><code>{
  a = "1.7";
  b = "0.08";
  c = "1.4";
  }
  </code></pre>
  
  <p>...to turn into this sorted dictionary...</p>
  
  <pre><code>{
  b = "0.08";
  c = "1.4";
  a = "1.7";
  }
  </code></pre>
  
  <p>But using that line of code from above returns the error "argument type anyobject does not conform with type NSCopying" for the <code>$0 &lt; $1</code> part. So how can I sort a dictionary by its values in Swift 3?</p>
  
  <p>(Note: That line of code came in part from <a href="https://stackoverflow.com/a/37816131/5700898">this answer</a>.)</p>
  
  <p>I am using <strong>Swift 3</strong> in <strong>Xcode 8 beta 1</strong>.</p>