I have an array of NSString
objects in the format... @"Aug 2013" @"July 2013" and so on...
I want to sort this array in ascending order
.. Is getting the date first for individual value a good idea..?
An other solution in one block
NSArray* array = [NSArray arrayWithObjects:@"Janvier 2012",@"Mars 2013", @"Juin 2013", @"Octobre 2012", nil];
NSArray* result = [array sortedArrayUsingComparator:^(id a, id b) {
NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
[dateFormat setDateFormat:@"MMMM YYYY"];
NSDate* datea = [dateFormat dateFromString:a];
NSDate* dateb = [dateFormat dateFromString:b];
return [datea compare:dateb];
}];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With