Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Example for when to use [NSCalendar autoupdatingCurrentCalendar]

I'm looking for an example where + autoupdatingCurrentCalendar would be used instead of + currentCalendar. More specifically where the values based on the calendar are automatically changed when the calendar changes. Do I need bindings for this or something like that?

The docs state:

Note that if you cache values based on the calendar or related information those caches will of course not be automatically updated by the updating of the calendar object.

Thanks in advance

like image 779
oliver223 Avatar asked Mar 08 '11 17:03

oliver223


2 Answers

currentCalendar returns cached version of current system calendar, while autoupdatingCurrentCalendar always returns most recent version of system calendar.

That is important, when you are presenting data based on the various parameters of a calendar like number of days in a month, number of a weeks in year or number of hours in a day.

To be honest, I don't know why Apple gives you an opportunity to get outdated value by using currentCalendar. It looks like they have internal API that allows you to manipulate caches of NSCalendar, so you can achieve better performance. But since it is not public, there is no reason to use currentCalendar.

That is, always use autoupdatingCurrentCalendar.

like image 88
Kentzo Avatar answered Sep 23 '22 02:09

Kentzo


Well, on OS X you can be running multiple processes simultaneous. One could be your process that uses the autoupdatingCurrentCalendar. The other could be System Preferences.

System Preferences allows you to customize your calendar settings. You can choose the first day of the week to be something other than the default (Sunday). Or you can choose a whole different calendar altogether. If you use the autoupdatingCurrentCalendar, these changes will be picked up automatically. If you don't use it, they won't.

like image 27
Dave DeLong Avatar answered Sep 23 '22 02:09

Dave DeLong