Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>There are three solutions:</p> <ol> <li>Put NSNumber instances into the dictionaries in place of the strings (e.g., <code>@"100"</code>) you currently have. NSNumber objects should compare themselves numerically.</li> <li><p>Send the array a <code>sortUsingComparator:</code> or <code>sortUsingFunction:context:</code> message instead of <code>sortUsingDescriptors:</code>, passing a block or function that retrieves the strings and compares them numerically (by sending them <a href="http://developer.apple.com/mac/library/documentation/Cocoa/Reference/Foundation/Classes/NSString_Class/Reference/NSString.html#//apple_ref/occ/instm/NSString/compare:options:" rel="nofollow noreferrer"><code>compare:options:</code></a> messages with the <code>NSNumericSearch</code> option).</p> <p>Note that the block or function will be passed the whole dictionaries, not the strings, since it has no way to know which strings to extract, so you'll have to get the strings out of the dictionaries yourself in order to compare them.</p></li> <li>Replace the dictionaries with <a href="http://developer.apple.com/mac/library/documentation/Cocoa/Conceptual/ModelObjects/" rel="nofollow noreferrer">model objects</a> that have <a href="http://developer.apple.com/mac/library/documentation/Cocoa/Conceptual/ObjectiveC/Articles/ocProperties.html#//apple_ref/doc/uid/TP30001163-CH17-SW1" rel="nofollow noreferrer">properties</a> in place of the dictionary keys. If you declare the property with a numeric type (e.g., <code>NSUInteger</code>), then when the array uses KVC to access the property, it will get NSNumber objects, which, as noted under #1 above, should compare themselves numerically.</li> </ol> <p>I would go with #3.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload