Aej11 Aej11 - 1 year ago 126
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)

Answer Source

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
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download