Re: Chronological sort descriptor?
Re: Chronological sort descriptor?
- Subject: Re: Chronological sort descriptor?
- From: Jeremy Dronfield <email@hidden>
- Date: Mon, 19 Jan 2004 20:43:51 +0000
On 19 Jan 2004, at 7:52 pm, Jonathan E. Jackel wrote:
for(x = 1; x < 13; x++)
{
NSCalendarData *aDate = [NSCalendarDate dateWithYear:2004
month:x day:10 hour:0 minute:0 second:0 timeZone:nil] ;
[aDate setCalendarFormat:@"%B"]
[dateArray addObject:aDate];
}
This should (NOT TESTED) generate an array of calendar dates in chron
order
that, when displayed, will show only the full month name. That is,
[[dataArray objectAtIndex:0] description] yields @"January". With an
unsorted array of calendar dates, you can use [dateArray
sortedArrayUsingSelector:@selector(compare:)] to get a sorted version.
(If
you wanted the months sorted alphabetically, you could make a sort
descriptor on the "description" key.)
Thank you. That's just the guidance I was looking for. With some
alterations to your code, I've come up with the following solution,
which works just as I want it:
int x;
NSMutableArray *tempMonthList;
tempMonthList = [[NSMutableArray alloc] initWithObjects:@"April",
@"August", @"December", @"February", @"January", @"July", @"June",
@"March", @"May", @"November", @"October", @"September", nil];
monthList = [[NSMutableArray alloc] init];
for(x = 0; x < [tempMonthList count]; x++)
{
NSCalendarDate *aDate = [NSCalendarDate dateWithString:[tempMonthList
objectAtIndex:x] calendarFormat:@"%B"];
[monthList addObject:aDate];
}
[monthList sortUsingSelector:@selector(compare:)];
[tempMonthList release];
monthList is then used to populate a table with a chronological list of
months. (In reality, tempMonthList is initialised with an alphabetical
list of strings from a directory, not as shown above). Thanks again.
-Jeremy
========================================
email@hidden
theLocustFarm.net:
- fractious fiction at
http://freespace.virgin.net/jeremy.dronfield
========================================
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.