Reputation: 2253
I have one array and in that having data like this.
(
{
avatar = "306_20160701_112934.jpg";
email = "[email protected]";
"full_name" = "hardik ";
number = 977743;
"user_id" = 306;
},
{
avatar = "profileImage_1466836096488.jpg";
email = "[email protected]";
"full_name" = "Robot Codol";
number = 903360;
"user_id" = 324;
},
{
avatar = "386_20160705_120501.jpg";
email = "[email protected]";
"full_name" = "apu ";
number = 46576246876;
"user_id" = 386;
},
{
avatar = "profileImage_1467293381491.jpg";
email = "[email protected]";
"full_name" = "Robot Codol";
number = 905660;
"user_id" = 402;
},
{
avatar = "474_20160704_073537.jpg";
email = "[email protected]";
"full_name" = "hardik ";
number = "+9777743";
"user_id" = 474;
}
)
Now I Want to sort this details in accending order by "full_name" Can you please help in this.
I have tried this code but cant do it.
NSSortDescriptor *sortDescriptor;
sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"full_name" ascending:YES];
NSArray *sortDescriptors = [NSArray arrayWithObject:sortDescriptor];
[arrSeggestedContact sortUsingDescriptors:sortDescriptors];
Help in this thank you.
Upvotes: 1
Views: 79
Reputation: 1698
NSSortDescriptor *fullNameSortDescriptor = [NSSortDescriptor sortDescriptorWithKey:@"full_name"
ascending:YES
selector:@selector(localizedStandardCompare:)];
NSLog(@"By Full name: %@", [people sortedArrayUsingDescriptors:@[fullNameSortDescriptor]]);
Upvotes: 2
Reputation: 82766
try this
NSSortDescriptor *sortDescriptor =[[[NSSortDescriptor alloc]
initWithKey:@"full_name"
ascending:YES
selector:@selector(localizedCaseInsensitiveCompare:)]; // or try with `caseInsensitiveCompare`
Upvotes: 3