Trigger notification weekly Swift 3

You can set your trigger to repeat every monday at 1:05am as follow: import UserNotifications let trigger = UNCalendarNotificationTrigger(dateMatching: DateComponents(hour: 1, minute: 5, weekday: 2), repeats: true) print(trigger.nextTriggerDate() ?? “nil”) let content = UNMutableNotificationContent() content.title = “title” content.body = “body” // make sure you give each request a unique identifier. (nextTriggerDate description) let request = … Read more

NSCalendar first day of week

Edit: This does not check the edge case where the beginning of the week starts in the prior month. Some updated code to cover this: https://stackoverflow.com/a/14688780/308315 In case anyone is still paying attention to this, you need to use ordinalityOfUnit:inUnit:forDate: and set firstWeekday to 2. (1 == Sunday and 7 == Saturday) Here’s the code: … Read more

tech