title: Sort Swift Array of Dictionaries by Value of a Key
body: <p>I am attempting to sort a Swift array which is composed of dictionaries.  I have prepared a working example below. The goal is to sort the entire array by the "d" element in the dictionaries. I have prepared this working example which can be placed into a Swift project:</p>
  
  <pre><code>var myArray = Array&lt;AnyObject&gt;()
  var dict = Dictionary&lt;String, AnyObject&gt;()
  
  dict["a"] = "hickory"
  dict["b"] = "dickory"
  dict["c"] = "dock"
  dict["d"] = 5
  
  myArray.append(dict)
  
  dict["a"] = "three"
  dict["b"] = "blind"
  dict["c"] = "mice"
  dict["d"] = 6
  
  myArray.append(dict)
  
  dict["a"] = "larry"
  dict["b"] = "moe"
  dict["c"] = "curly"
  dict["d"] = 2
  
  myArray.append(dict)
  
  println(myArray[0])
  println(myArray[1])
  println(myArray[2])
  }
  </code></pre>
  
  <p>This results in the following output to the log:</p>
  
  <pre><code>{
      a = hickory;
      b = dickory;
      c = dock;
      d = 5;
  
  }
  {
      a = three;
      b = blind;
      c = mice;
      d = 6;
  }
  {
      a = larry;
      b = moe;
      c = curly;
      d = 2;
  }
  </code></pre>
  
  <p>The goal is to sort the array by the "d" element, so that the above output would be changed to the following (which is based on numerical order of "d": '2, 5, 6'):</p>
  
  <pre><code>{
      a = larry;
      b = moe;
      c = curly;
      d = 2;
  }
  {
      a = hickory;
      b = dickory;
      c = dock;
      d = 5;
  }
  {
      a = three;
      b = blind;
      c = mice;
      d = 6;
  }
  </code></pre>
  
  <p>There are some other questions that seem similar, but when you look at them, it becomes clear they are not addressing this. Thank you for your assistance.</p>