I am trying to set a repeatingInterval of a UILocalNotification using these values but, as always, Apple docs are vague as hell.
Any clues?
thanks.
Maybe look at this blog I just found about the subject?
AFAIK, NSCalendarUnits
are primarely used to split a date or timeInterval into date components (NSDateComponents
), to extract the weekday of a date, the year of the date, the hour component of a time, and so on.
In this context:
NSWeekCalendarUnit
of a date correspond to the week index in the year (from 1st to 52nd week - or 53rd for years with 53 weeks)NSWeekdayCalendarUnit
corresponds to the day in the week (from Mon to Sun)NSDayCalendarUnit
corresponds to the day in the year (from 1 to 365)When using the NSCalendarUnit type with repeatingInterval
, the UILocalNotification will be triggered when the corresponding unit changes:
NSWeekCalendarUnit
will trigger the notification every week (every 7 days)NSWeekdayCalendarUnit
will trigger the notification "every weekday", which corresponds to the same thing here as NSDayCalendarUnit
which corresponds to "every day" in the context of a repeatingInterval.Cocoa and Objective-C make it easy to knock up quick test programs to see results. If you aren't sure of the documentation you can always check for yourself. I've got a project that builds a Foundation Command Line tool, and I just type these snippets into the main.m and log them just to see what the API returns.
For example, I just ran this:
unsigned flags = NSWeekCalendarUnit;
NSDateComponents *components = [[NSCalendar currentCalendar] components:flags fromDate:[NSDate date]];
NSLog(@"Week: %ld", [components week]);
flags = NSWeekdayCalendarUnit;
components = [[NSCalendar currentCalendar] components:flags fromDate:[NSDate date]];
NSLog(@"WeekDay: %ld", [components weekday]);
And got
Week: 37
Weekday: 7
It's quick to see that WeekCalendar unit gives this as the 37th week of the year and WeekDay says this (it's Saturday today) is the 7th day of the week ('cos I know that the Gregorian calendar counts Sunday as day 1).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With