統計情報(30日間)


最新情報をツイート


人気の投稿

NSDate-Extension

このエントリーをはてなブックマークに追加



[[NSDate date] get:@(8).days.ago];
とか書ける。

NSNumberにカテゴリで daysやmonthsを追加して上記のような記法にしている。中心部分は表(おもて)に見えない NSDateComponentsのカテゴリ。KVCを駆使して ago や before を実現していてなかなかおもしろかった。

このコードで初めて知ったのが NSCalendar.autoupdatingCurrentCalendar

リファレンスによれば
Discussion
Settings you get from this calendar do change as the user’s settings change (contrast with currentCalendar).

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.
とのこと。ユーザ設定が反映された currentCalendarということか。その逆に currentCalendarはキャッシュされた情報を使っているのか?




StackOverflowの回答によれば 
But since it is not public, there is no reason to use currentCalendar.

That is, always use autoupdatingCurrentCalendar.
ふーむ。




(オチ無し)

Leave a Reply