title: Sorting a NSMutable Dictionary
body: <p>Any pointers for the right direction would be gratefully received,</p>
  
  <p>I have a NSDictionary of the format:</p>
  
  <pre><code>{
  3 = "special-collection-procedures-see-notes|";
  13 = "&lt;p&gt;None Given&lt;/p&gt;";
  16 = "";
  6 = "&lt;p&gt;Arrange for sample to be separated at an interim site and subsequently transport frozen to lab, if it cannot reach lab within one hour.&lt;/p&gt;";
  9 = "&lt;p&gt;Stored in laboratory at -20C&lt;/p&gt;";
  12 = "&lt;p&gt;None&lt;/p&gt;";
  2 = "images/tubes/lightblue_tube_large.png";
  15 = "";
  5 = "";
  8 = "Up to 28 days";
  11 = "&lt;p&gt;Some indications: Hereditary Angioedema&lt;/p&gt;&lt;p&gt;Sample type is citrated plasma though plain serum can also be used.&lt;/p&gt;";
  1 = " Functional C1 esterase inhibitor";
  14 = "|";
  4 = "5-10 mL";
  7 = "&lt;p&gt;Frozen if unable to deliver within one hour&lt;/p&gt;";
  10 = "&lt;p&gt;expressed as a percentage of a control serum with 75% -125% being classed as normal.&lt;/p&gt;";
  </code></pre>
  
  <p>}</p>
  
  <p>Which I would like to sort the keys so that the order is:</p>
  
  <pre><code>1 = " Functional C1 esterase inhibitor";
  2 = "images/tubes/lightblue_tube_large.png";
  </code></pre>
  
  <p>Etc.</p>
  
  <p>I have this piece of code:</p>
  
  <pre><code>NSArray *myArray; 
  
  myArray = [[valuesDictionary allKeys] sortedArrayUsingComparator: ^(id obj1, id obj2) {
  
      if ([obj1 integerValue] &gt; [obj2 integerValue]) {
  
          return (NSComparisonResult)NSOrderedDescending;
      }
      if ([obj1 integerValue] &lt; [obj2 integerValue]) {
  
          return (NSComparisonResult)NSOrderedAscending;
      }
  
      return (NSComparisonResult)NSOrderedSame;
  }];
  
  NSMutableDictionary *sortedDisplay = [[NSMutableDictionary alloc] init];
  
  for (id object in myArray) {
      // do something with object
      [sortedDisplay setObject:[valuesDictionary objectForKey:object] forKey:object];
  
  }
  </code></pre>
  
  <p>Which gives me a sorted myArray:
  1,
  2,
  3,
  4,
  5,
  6,
  7,
  8,
  9,
  10,
  11,
  12,
  13,
  14,
  15,
  16</p>
  
  <p>But the final "sorted" mutable dictionary is not sorted i.e its</p>
  
  <p>Printing description of sortedDisplay:</p>
  
  <pre><code>{
  13 = "&lt;p&gt;None Given&lt;/p&gt;";
  12 = "&lt;p&gt;None&lt;/p&gt;";
  11 = "&lt;p&gt;Some indications: Hereditary Angioedema&lt;/p&gt;&lt;p&gt;Sample type is citrated plasma though plain serum can also be used.&lt;/p&gt;";
  7 = "&lt;p&gt;Frozen if unable to deliver within one hour&lt;/p&gt;";
  6 = "&lt;p&gt;Arrange for sample to be separated at an interim site and subsequently transport frozen to lab, if it cannot reach lab within one hour.&lt;/p&gt;";
  2 = "images/tubes/lightblue_tube_large.png";
  1 = " Functional C1 esterase inhibitor";
  14 = "|";
  15 = "";
  10 = "&lt;p&gt;expressed as a percentage of a control serum with 75% -125% being classed as normal.&lt;/p&gt;";
  9 = "&lt;p&gt;Stored in laboratory at -20C&lt;/p&gt;";
  8 = "Up to 28 days";
  5 = "";
  4 = "5-10 mL";
  3 = "special-collection-procedures-see-notes|";
  16 = "";
  </code></pre>
  
  <p>}</p>
  
  <p>What am I doing wrong?</p>