iPhone - what is the difference between NSWeekCalendarUnit and NSWeekdayCalendarUnit?

后端 未结 3 1175
温柔的废话
温柔的废话 2021-01-03 01:28

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.

3条回答
  •  春和景丽
    2021-01-03 01:55

    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:

    • the 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.

提交回复
热议问题