I have an NSMutableArray containing abbreviated days of the week, sun, mon, tue, wed, thu, fri, sat. I am trying to sort it so that they will always be in this order, no matter which days are there, and/or their current order. How do I sort the string so that they are always in the right order?
I tried using
NSArray* sorted = [parent.medication.days sortedArrayUsingComparator:^NSComparisonResult(NSString* obj1, NSString* obj2) {
// sort by position of id string in order array..
NSUInteger obj1Pos = [idsInOrder indexOfObject:obj1[@"sun"] ];
NSUInteger obj2Pos = [idsInOrder indexOfObject:obj2[@"mon"] ];
return [[NSNumber numberWithInteger:obj1Pos] compare:[NSNumber numberWithInteger:obj2Pos]];
}];
But all that did was throw errors on me, and it didn't even include all 7 days.