title: How can i count and sort a NSMutableArray duplicate values
body: <p>I've seen this question:<br>
      <a href="https://stackoverflow.com/questions/6276830/nsmutablearray-counting-occurances-of-objects-and-then-re-arange-the-array">NSMutableArray counting occurances of objects and then re-arange the array</a></p>
  
  <p>The solution comes very close to what i need. </p>
  
  <p>The solution I'm referring to:</p>
  
  <pre><code>NSInteger countedSort(id obj1, id obj2, void *context) {
     NSCountedSet *countedSet = context;
     NSUInteger obj1Count = [countedSet countForObject:obj1];
     NSUInteger obj2Count = [countedSet countForObject:obj2];
  
     if (obj1Count &gt; obj2Count) return NSOrderedAscending;
     else if (obj1Count &lt; obj2Count) return NSOrderedDescending;
     return NSOrderedSame;
  }    
  </code></pre>
  
  <p>and:</p>
  
  <pre><code>NSMutableArray *array = …;
  
  NSCountedSet *countedSet = [[[NSCountedSet alloc] initWithArray:array]
  autorelease];
  
  [array sortUsingFunction:countedSort context:countedSet];    
  </code></pre>
  
  <p>The sort returns proper sorted array by count, but i need the count either included or in another array sorted ascending.</p>