Possible Duplicate:
Sort NSArray of date strings or objects
I want to sort an array which contain Dates in ascending order
Possible Duplicate:
Sort NSArray of date strings or objects
I want to sort an array which contain Dates in ascending order
it is a very generic way to sort any NSArray
with any type of objects, using blocks. now, it just is specified as solution for your current problem with the NSDate
objects.
NSArray *_arrayOfDates = // your array with the NSDate objects;
NSArray *_sortedArrayOfDates = [_arrayOfDates sortedArrayUsingComparator:^NSComparisonResult(id obj1, id obj2) {
return [((NSDate *) obj1) compare:((NSDate *)obj2)];
}];
NSLog(@"%@", _sortedArrayOfDates);
please note: you can use NSMutableArray
with -sortUsingComparator:
method, which provides the same result, but the array will be sorted inside of itself.
Try this:
NSLog(@"livevideoparsingarray..%@",livevideoparsingarray);
NSSortDescriptor * descLastname = [[NSSortDescriptor alloc] initWithKey:@"active" ascending:YES];
[livevideoparsingarray sortUsingDescriptors:[NSArray arrayWithObjects:descLastname, nil]];
[descLastname release];
videoparsing = [livevideoparsingarray copy];
livevideoparsingarray is my array which I have sort & active is my tag which is in array which I have sort. You change with your requirements.