Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IOS need to sort an array of dictionaries value based on key price

Tags:

ios

iphone

'm facing problem to sort the values based on key using dictionary object. Actually what i am storing is, each dictionary object having different data type in that dictionary all the data type taking as a string how to convert this string type to specific data type and sort it price vise, my code and out put is bellow, Please help me on this one.

-(IBAction)PriceSort:(id)sender
{
    NSSortDescriptor * sort = [[NSSortDescriptor alloc] initWithKey:@"Price" ascending:true] ;
    NSArray *sa = [symbolArray sortedArrayUsingDescriptors:[NSArray arrayWithObject:sort]];
    NSLog(@"price=%@",sa);

}

out put {

    volume = 2496752;

    Yield = "10.49";

    MarCap = 829;

    Price = "0.715";

    Symbol = SAIPI;

},
like image 331
Vijay Avatar asked Mar 23 '13 07:03

Vijay


People also ask

How to sort dictionary by value in Python?

How to sort dictionary by value in Python? In Python, the dictionary class doesn't have any provision to sort items in its object. Hence, some other data structure, such as the list has to be used to be able to perform sorting. To begin with, our test data is following dictionary object having names and marks of students.

How do I get the value of a dictionary key?

To get the value for a particular key in a dictionary, you can use the Get Dictionary Value action and specify the name of the key. To get an object’s phone value, add the Get Dictionary Value action and set it to phone. If you want the company name, you can use the dot notation company.name, as shown in the screenshot below.

How to reconstruct dictionary in sorted order of marks in Python?

The itemgetter () function returns a callable object from its operand. Finally, we shall use the dict.items () method along with the sorted () function to first obtain (marks, name) tuples and then reconstruct dictionary in a sorted order of marks.

Which data structure should be used to perform sorting?

Hence, some other data structure, such as the list has to be used to be able to perform sorting. To begin with, our test data is following dictionary object having names and marks of students.


1 Answers

 sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"price"
                                                 ascending:YES selector:@selector(localizedStandardCompare:)] ;

Please replace this one and try , hope its works .

like image 122
Krish Allamraju Avatar answered Nov 15 '22 00:11

Krish Allamraju