Skip to content

Instantly share code, notes, and snippets.

View ariok's full-sized avatar
🧠
CodeLoving

Yari @bitwaker ariok

🧠
CodeLoving
View GitHub Profile
//Request the access to the Calendar
[eventStore requestAccessToEntityType:EKEntityTypeEvent
completion:^(BOOL granted,NSError* error){
//Access not granted-------------
if(!granted){
}
@ariok
ariok / [CustomContainers]SingleChildAnimated.m
Last active October 18, 2017 18:31
Add/Remove a single child ViewController
// 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
+ (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];
@ariok
ariok / [CoreData]SQLDebug
Created November 29, 2013 16:52
Enabling Core Data SQL Debug mode
// From your project -> Edit scheme
// Tab "Run"
// Section "Argument passed at Lauch"
// Add this argument
-com.apple.CoreData.SQLDebug 1
@ariok
ariok / [CoreData]EntriesBetweenDates.m
Created November 29, 2013 17:01
Get Core Data entries between a date range
+ (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];
@ariok
ariok / [Date]MonthFirstLastDays.m
Created November 29, 2013 17:18
Get the NSDate representations of the first and last days of the given month in the specified year
// 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
@ariok
ariok / [Date]ResetTime.m
Created November 29, 2013 17:39
Reset the time of an NSDate to 00:00:00 (Note: GMT+1 is 23:00:00 etc.. )
// 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;
}
@ariok
ariok / [Date]UnitForDate.m
Last active December 29, 2015 18:19
Return the integer representation of the required unit for the given date Note: this functions assumes that the current calendar is set to Gregorian and takes as units year, month,day, hour,minute and second.
// 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];
@ariok
ariok / [Date]MonthName.m
Created November 29, 2013 18:18
Get the month name from its numeric representation
// 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;
}
@ariok
ariok / [UI]LoadWithXib.m
Created December 2, 2013 16:32
Loading the main view from a xib file
- (UIView *)loadWithNib {
NSArray *aNib = [[NSBundle mainBundle]loadNibNamed:NSStringFromClass([self class]) owner:self options:nil];
UIView *view = [aNib objectAtIndex:0];
return view;
}