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

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -