objective c - NSSortDescriptor Order Values Less than 10.0 -


nssortdescriptor not ordering correct when distance less 10.0.

code (order array distance):

// order array distance (distance = nsstring) nssortdescriptor *asortdescriptor = [[nssortdescriptor alloc] initwithkey:@"distance" ascending:yes]; [_contentdata sortusingdescriptors:[nsarray arraywithobject:asortdescriptor]]; 

right ordering (when distance values > 10.0):

    (             {             distance = "11.256649";         },             {            distance = "257.428821";         },             {             distance = "4534.256851";         }     ) 

wrong ordering (when distance value < 10.0):

    (             {            distance = "252.428821";         },             {             distance = "4514.256851";         }             {             distance = "8.362996"; // wrong ordering when distance < 10.0         },     ) 

i don't think issue here value less 10. appears values strings, , being ordered character character. "8" comes after "4", it's ordered later.

if convert string values nsnumbers, should sort properly.


Comments

Popular posts from this blog

Eclipse formatter for java ending braces -

ruby - Nesting modules inside of a Rails eninge gem -

php - Why I am getting the Error "Commands out of sync; you can't run this command now" -