Aej11 Aej11 - 6 months ago 52
Swift Question

How to use NSCalendarDayChanged - swift

The following code isn't working (isn't activating calendarDayDidChange) when the date changes:

// Define identifier
let notificationName = Notification.Name("NSNotification.Name.NSCalendarDayChanged")

// Register to receive notification
NotificationCenter.default.addObserver(self, selector: #selector(calendarDayDidChange(notification:)), name: notificationName, object: nil)

The method header is

func calendarDayDidChange(notification : NSNotification)


NSCalendarDayChanged is already of type NSNotification.Name so you don't need to cast it.

let notificationName: Notification.Name = .NSCalendarDayChanged


let notificationName = Notification.Name.NSCalendarDayChanged