I have object Item
and it has only two NSDate
properties.
From those properties only important part for me is time.
If it is possible this doesn't have to be NSDate it can be NSString with just a @"14:30"
and @"17:30"
.
I have 10 objects with different times and they are in NSMutableArray
.
I need to sort all those objects to load them in table.
I have tried something but no luck (actually this code works for one property) with two properties:
NSDate *now = [NSDate date];
NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
NSDateComponents *components = [calendar components:NSYearCalendarUnit|NSMonthCalendarUnit|NSDayCalendarUnit fromDate:now];
[components setHour:12];
NSDate *todayA = [calendar dateFromComponents:components];
[components setHour:11];
NSDate *todayB = [calendar dateFromComponents:components];
[components setHour:10];
NSDate *todayC = [calendar dateFromComponents:components];
Item* i1 = [[Item alloc] init];
i1.DateTimeA = todayA;
Item* i2 = [[Item alloc] init];
i2.DateTimeA = todayB;
Item* i3 = [[Item alloc] init];
i3.DateTimeA = todayC;
[array addObject:i1];
[array addObject:i2];
[array addObject:i3];
NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"DateTimeA" ascending:NO];
NSArray *orderedArray = [array sortedArrayUsingDescriptors:[NSArray arrayWithObject:sortDescriptor]];
As I said Item
DateTimeA
and DateTimeB
doesn't have to be NSDate
they can be only strings but I must be able to sort by those two properties.
Is there any solution for this?