4

The documentation for NSDateComponents says that as of iOS 7, week is deprecated and to use weekOfDay or weekOfYear instead.

If I want to get the same logic as I got when I used week, which of these should I use?

I have used this in many places in my code, so thinking through each scenario is cumbersome. If there was one enum that mapped to the same thing that week originally did, it would save a lot of time.

Senseful
  • 86,719
  • 67
  • 308
  • 465
  • See http://stackoverflow.com/questions/25399256/nsdatecomponents-difference-between-weekofyear-and-weekofmonth – rmaddy Sep 10 '14 at 22:41

1 Answers1

10

Didn't find anything in the documentation, but i have this in my code:

    NSDateComponents *todayComps =
    [calendar components:NSYearCalendarUnit | NSMonthCalendarUnit | NSWeekdayCalendarUnit | NSWeekCalendarUnit
                fromDate:[NSDate date]];

When i printed todayComps.week to the console i got 39.

So i think you should replace todayComps.week with todayComps.weekOfYear.

Don't forget to use NSWeekOfYearCalendarUnit instead of NSWeekCalendarUnit.

Good luck!

chents
  • 393
  • 3
  • 14