Note that there are some explanatory texts on larger screens.

plurals
  1. POSort an Array of Dictionaries issue
    text
    copied!<p>I have an array(seachResult) which contains dictionaries and I want to sort this array according to 'price' key in the dictionary that is a number in string format. I tried this code but it doesn't work for sorting 'price' but it works for pid which is a number. how can I sort it according 'price' (number in string format)?</p> <pre><code> NSSortDescriptor *sortByPrice = [NSSortDescriptor sortDescriptorWithKey:@"price" ascending:YES]; NSArray *sortDescriptors = [NSArray arrayWithObject:sortByPrice]; NSArray *sortedArray = [self.seachResult sortedArrayUsingDescriptors:sortDescriptors]; NSLog(@"%@",sortedArray ); </code></pre> <p>here is sample data for self.searchResult:</p> <pre><code>2013-07-17 02:04:55.012 MyApp[57014:16a03] sorted array of dictionaries: ( { cid = 2; image = "http:///images/loginlogo.png"; latitude = "48.245565"; longitude = "16.342333"; manual = ""; movie = "http://jplayer.org/video/m4v/Big_Buck_Bunny_Trailer.m4v"; pcode = 023942435228; pid = 1; pname = "example product"; price = "12.00"; qrcode = ""; rid = 1; rname = "Example Retailer Name"; sale = 0; "sale_percent" = 0; "sale_price" = "0.00"; text = "here is text about sample product number 1...\nasdasdasda\nsdfsdfsd\nSdfsdf\nSDfsdfs\ndfsdfsdf\n\n\n"; }, { cid = 2; image = "http:///testImage.png"; latitude = "48.245565"; longitude = "16.342333"; manual = ""; movie = ""; pcode = 1; pid = 2; pname = "sample product 2"; price = "126.00"; qrcode = ""; rid = 1; rname = "Example Retailer Name"; sale = 1; "sale_percent" = 20; "sale_price" = "99.99"; text = "here is text about sample product number 2...\nblah blah blah\nasdasdasd\nASdasdas\nASdasdasd"; }, { cid = 1; image = ""; latitude = ""; longitude = ""; manual = ""; movie = ""; pcode = 1; pid = 3; pname = "test product"; price = "46.00"; qrcode = ""; rid = 2; rname = ""; sale = 0; "sale_percent" = 0; "sale_price" = "35.00"; text = "some text here... </code></pre> <p>\nasdasd \nasd \na \nsd \nas \nd"; } )</p> <p>I also tried this code :</p> <pre><code> NSSortDescriptor *hopProfileDescriptor = [[NSSortDescriptor alloc] initWithKey:@"price" ascending:YES]; NSArray *descriptors = [NSArray arrayWithObjects:hopProfileDescriptor, nil]; NSArray *sortedArrayOfDictionaries = [self.seachResult sortedArrayUsingDescriptors:descriptors]; NSLog(@"sorted array of dictionaries: %@", sortedArrayOfDictionaries); </code></pre> <p>but still doesn't work.</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