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
- (Entry*)entryForDate:(NSDate *)date inContext:(NSManagedObjectContext*)context{ | |
NSFetchRequest *request = [[NSFetchRequest alloc]initWithEntityName:@"Entry"]; | |
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"since >= %@",date]; | |
request.predicate = predicate; | |
NSSortDescriptor *sort = [NSSortDescriptor sortDescriptorWithKey:@"since" ascending:YES]; | |
request.sortDescriptors = @[sort]; | |
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
- (UIView *)loadWithNib { | |
NSArray *aNib = [[NSBundle mainBundle]loadNibNamed:NSStringFromClass([self class]) owner:self options:nil]; | |
UIView *view = [aNib objectAtIndex:0]; | |
return view; | |
} |
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
// Return the month name | |
+ (NSString*)monthName:(NSInteger)month{ | |
NSDateFormatter *formatter = [[NSDateFormatter alloc] init]; | |
formatter.locale = [NSLocale currentLocale]; | |
NSString *monthName = [[formatter monthSymbols] objectAtIndex:(month - 1)]; | |
return monthName; | |
} |
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
// Return integer representation of the required unit for the given date | |
// Note: It assumes that the current calendar is set to Gregorian | |
+ (NSInteger)unit:(NSCalendarUnit)unit forDate:(NSDate*)date{ | |
// Get the calendar | |
NSCalendar *calendar = [[NSCalendar alloc]initWithCalendarIdentifier:NSGregorianCalendar]; | |
[calendar setTimeZone:[NSTimeZone defaultTimeZone]]; | |
// Get the component | |
NSDateComponents *componets = [calendar components:unit fromDate:date]; |
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
// Reset the time information to 00:00:00 | |
- (NSDate*)resetTimeForDate:(NSDate*)date{ | |
NSDateComponents *components = [[NSCalendar currentCalendar] components:NSYearCalendarUnit|NSMonthCalendarUnit|NSDayCalendarUnit | |
fromDate:date]; | |
[components setTimeZone:[NSTimeZone defaultTimeZone]]; | |
NSDate *clearedDate = [[NSCalendar currentCalendar] dateFromComponents:components]; | |
return clearedDate; | |
} |
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
// Return an array: | |
// Index 0: NSDate for the First day of the month | |
// Index 1: NSDate for the Last day of the month | |
+ (NSArray *)dateRangeForYear:(NSInteger)year Month:(NSInteger)month{ | |
// Build calendar and date components | |
NSCalendar* calendar = [NSCalendar currentCalendar]; | |
NSDateComponents* dateComps = [[NSDateComponents alloc] init]; | |
// Set the month |
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
+ (NSArray*)allEntriesInContext:(NSManagedObjectContext*)context fromDate:(NSDate*)fromDate toDate:(NSDate*)toDate{ | |
// Create the request | |
NSFetchRequest *request = [[NSFetchRequest alloc]initWithEntityName:@"Entry"]; | |
// Build the predicate | |
NSPredicate *predicate = [NSPredicate predicateWithFormat: @"date >= %@ && date <= %@ ", fromDate, toDate]; | |
request.predicate = predicate; | |
// Define sorting | |
NSSortDescriptor *sortDesc = [NSSortDescriptor sortDescriptorWithKey:@"date" ascending:YES]; | |
request.sortDescriptors = @[sortDesc]; |
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
// From your project -> Edit scheme | |
// Tab "Run" | |
// Section "Argument passed at Lauch" | |
// Add this argument | |
-com.apple.CoreData.SQLDebug 1 |
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
+ (NSDate *)dateWithYear:(NSInteger)year month:(NSInteger)month day:(NSInteger)day { | |
NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar]; | |
NSDateComponents *components = [[NSDateComponents alloc] init]; | |
[components setYear:year]; | |
[components setMonth:month]; | |
[components setDay:day]; | |
return [calendar dateFromComponents:components]; |
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
// Add Remove child controllers to a custom container controller with Animations | |
// ADD THE CHILD CONTROLLER | |
self.childController = theChildController; | |
self.childController.view.frame = setupInitialChildControllerFrame(); | |
[self addChildViewController:self.childController]; | |
[self.view addSubview:self.childController.view]; | |
[self.childController didMoveToParentViewController:self]; | |
[UIView animateWithDuration:1.0 | |
delay:0.0 |