Created
August 3, 2011 18:38
-
-
Save nathanclark/1123443 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #import <Foundation/Foundation.h> | |
| #import <CoreData/CoreData.h> | |
| @class Assignment; | |
| @interface Chore : NSManagedObject | |
| @property (nonatomic, retain) NSString * name; | |
| @property (nonatomic, retain) NSNumber * doMonday; | |
| @property (nonatomic, retain) NSNumber * doSunday; | |
| @property (nonatomic, retain) NSNumber * doWednesday; | |
| @property (nonatomic, retain) NSNumber * coins; | |
| @property (nonatomic, retain) NSNumber * doThursday; | |
| @property (nonatomic, retain) NSNumber * difficulty; | |
| @property (nonatomic, retain) NSNumber * doFriday; | |
| @property (nonatomic, retain) NSString * instructions; | |
| @property (nonatomic, retain) NSNumber * doTuesday; | |
| @property (nonatomic, retain) NSNumber * doSaturday; | |
| @property (nonatomic, retain) NSNumber * weekly; | |
| @property (nonatomic, retain) NSDate * date; | |
| @property (nonatomic, retain) NSNumber * weekNumber; | |
| @property (nonatomic, retain) NSNumber * doThisWeek; | |
| @property (nonatomic, retain) NSSet *assignment; | |
| @property (readonly, copy) NSSet *players; | |
| @property (nonatomic, retain) NSNumber * thisWeeks; | |
| -(NSString*)days; | |
| -(NSString*)daysNoCommas; | |
| -(UIView*)complexityLabel; | |
| @end | |
| @interface Chore (CoreDataGeneratedAccessors) | |
| - (void)addAssignmentObject:(Assignment *)value; | |
| - (void)removeAssignmentObject:(Assignment *)value; | |
| - (void)addAssignment:(NSSet *)values; | |
| - (void)removeAssignment:(NSSet *)values; | |
| @end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #import "Chore.h" | |
| #import "Assignment.h" | |
| #import "YRLabel.h" | |
| @implementation Chore | |
| @dynamic name; | |
| @dynamic doMonday; | |
| @dynamic doSunday; | |
| @dynamic doWednesday; | |
| @dynamic coins; | |
| @dynamic doThursday; | |
| @dynamic difficulty; | |
| @dynamic doFriday; | |
| @dynamic instructions; | |
| @dynamic doTuesday; | |
| @dynamic doSaturday; | |
| @dynamic weekly; | |
| @dynamic date; | |
| @dynamic weekNumber; | |
| @dynamic doThisWeek; | |
| @dynamic assignment; | |
| - (NSSet *)players { | |
| // use aggregate KVC to do the iteration automatically | |
| return [self.assignment valueForKey:@"player"]; | |
| } | |
| -(NSNumber *) doThisWeek{ | |
| if ([self.weekly boolValue]) { | |
| return [NSNumber numberWithBool:YES] ; | |
| } | |
| NSCalendar *calendar = [NSCalendar currentCalendar]; | |
| NSUInteger unitFlags = NSWeekCalendarUnit; | |
| NSDateComponents *dateComponents = [calendar components:unitFlags fromDate:[NSDate date]]; | |
| NSUInteger week = [dateComponents week]; | |
| if ([self.weekNumber intValue] % 2) | |
| if (week % 2) | |
| return [NSNumber numberWithBool:YES] ; | |
| if (!week % 2) | |
| if (![self.weekNumber intValue] % 2) | |
| return [NSNumber numberWithBool:YES] ; | |
| return [NSNumber numberWithBool:NO] ; | |
| } | |
| -(NSString*)days{ | |
| NSArray *daysMap = [NSArray arrayWithObjects:@"M", @"Tu", @"W", @"Th",@"F",@"Sa",@"Su",nil]; | |
| // NSMutableString *days = @""; | |
| NSSortDescriptor *alphaSort = [NSSortDescriptor sortDescriptorWithKey:@"day" ascending:YES]; | |
| NSArray *children = [[self.assignment allObjects] sortedArrayUsingDescriptors:[NSArray arrayWithObject:alphaSort]]; | |
| // [self.assignment allObjects] | |
| NSMutableArray *allDays = [[NSMutableArray alloc] init]; | |
| for (Assignment *ass in children) { | |
| [allDays addObject:ass.day]; | |
| } | |
| NSMutableArray * unique = [NSMutableArray array]; | |
| NSMutableSet * processed = [NSMutableSet set]; | |
| for (NSNumber * number in allDays) { | |
| if ([processed containsObject:number] == NO) { | |
| [unique addObject:number]; | |
| [processed addObject:number]; | |
| NSLog(@"Sorted array %i", [number intValue]); | |
| } | |
| } | |
| NSMutableString *returnDays = [[NSMutableString alloc] init]; | |
| for (NSNumber *thisDay in unique) { | |
| [returnDays appendFormat:@", %@", [daysMap objectAtIndex:[thisDay intValue]]]; | |
| } | |
| NSRange range; | |
| range.location = 0; | |
| range.length = 1; | |
| if ([allDays count] > 0) { | |
| [returnDays deleteCharactersInRange:range]; | |
| NSLog(@"Days %@", returnDays); | |
| } | |
| NSString *s = [[NSString alloc] initWithString:returnDays]; | |
| [allDays release]; | |
| [returnDays release]; | |
| return [s autorelease]; | |
| } | |
| -(NSString*)daysNoCommas{ | |
| NSArray *daysMap = [NSArray arrayWithObjects:@"M", @"Tu", @"W", @"Th",@"F",@"Sa",@"Su",nil]; | |
| // NSMutableString *days = @""; | |
| NSSortDescriptor *alphaSort = [NSSortDescriptor sortDescriptorWithKey:@"day" ascending:YES]; | |
| NSArray *children = [[self.assignment allObjects] sortedArrayUsingDescriptors:[NSArray arrayWithObject:alphaSort]]; | |
| // [self.assignment allObjects] | |
| NSMutableArray *allDays = [[NSMutableArray alloc] init]; | |
| for (Assignment *ass in children) { | |
| [allDays addObject:ass.day]; | |
| } | |
| NSMutableArray * unique = [NSMutableArray array]; | |
| NSMutableSet * processed = [NSMutableSet set]; | |
| for (NSNumber * number in allDays) { | |
| if ([processed containsObject:number] == NO) { | |
| [unique addObject:number]; | |
| [processed addObject:number]; | |
| NSLog(@"Sorted array %i", [number intValue]); | |
| } | |
| } | |
| NSMutableString *returnDays = [[NSMutableString alloc] init]; | |
| for (NSNumber *thisDay in unique) { | |
| [returnDays appendFormat:@" %@", [daysMap objectAtIndex:[thisDay intValue]]]; | |
| } | |
| NSRange range; | |
| range.location = 0; | |
| range.length = 1; | |
| NSString *s = [[NSString alloc] initWithString:returnDays]; | |
| [allDays release]; | |
| [returnDays release]; | |
| return [s autorelease]; | |
| } | |
| -(UIView*)complexityLabel{ | |
| switch ([self.coins intValue]) { | |
| case 1: | |
| return [YRLabel choreLabel:@"EASY" :0 :@"07ba26" :12]; | |
| break; | |
| case 3: | |
| return [YRLabel choreLabel:@"MEDIUM" :0 :@"e59d0a" :12]; | |
| break; | |
| case 5: | |
| return [YRLabel choreLabel:@"HARD" :0 :@"c85957" :12]; | |
| break; | |
| default: | |
| return [YRLabel choreLabel:@"HARD" :0 :@"c85957" :12]; | |
| break; | |
| } | |
| return nil; | |
| } | |
| @end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| NSPredicate *predicate = [NSPredicate predicateWithFormat: | |
| @"player == %@ AND (day == %@ OR day == %@) AND chore.doThisWeek == YES", | |
| player, | |
| [NSNumber numberWithInt:[self todaysDayNumber]], | |
| [NSNumber numberWithInt:[self yesterdaysDayNumber]]]; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment