24

In iOS 7.0 the NSWeekCalendarUnit has been deprecated. The documentation says it has to be replaced:

Use NSCalendarUnitWeekOfMonth or NSCalendarUnitWeekOfYear, depending on which you mean

I am using NSWeekCalendarUnit for weekly reminders, which one do I have to pick to get the same meaning? I dont understand the difference between NSCalendarUnitWeekOfMonth and NSCalendarUnitWeekOfYear.

Someone has asked the same question here on SO, without an convincing answer.

It quite confusing. Next week is in my understanding atomic. Today is Sun 30 March 2014. Hence Next week will always be Sun 6 March 2014. How could that change from a month or year perspective?

Community
  • 1
  • 1
Houman
  • 64,245
  • 87
  • 278
  • 460
  • Normally, NSCalendarUniwWeekOfMonth will return 1 for the first week of the month, whatever is the value of month, whereas NSCalendarUnitWeekOfYear will return differents values (there are around 52 weeks in a year, against 4/5 in a month). – Larme Mar 30 '14 at 13:46
  • Thanks and what does that mean in context of UILocalNotification? :) – Houman Mar 30 '14 at 13:53
  • 1
    I'd suggest to use NSCalendarUnitWeekOfYear to get a reminder each year, because I think that using NSCalendarUnitWeekOfMonth will for only for the current month (value going to 1 to 4). To debug, add a week to a date, iterate seeing theses two values of NSDateComponents. – Larme Mar 30 '14 at 13:57

1 Answers1

22

If you were using NSWeekCalendarUnit to trigger a weekly reminder, replace it with NSCalendarUnitWeekOfYear:

if (days == 7) localNotif.repeatInterval = NSWeekCalendarUnit;        // deprecated
if (days == 7) localNotif.repeatInterval = NSCalendarUnitWeekOfYear;

You should find your weekly notification still works correctly.

Apple's documentation should be updated to provide guidance on the appropriate replacement.

russes
  • 1,110
  • 11
  • 17