问题
I currently have this code below to see if the day has elapsed, but it doesn't seem to be working. Have I coded this correctly?
NotificationCenter.default.addObserver(self, selector:"calendarDayDidChange:", name:NSNotification.Name.NSCalendarDayChanged, object:nil)
func calendarDayDidChange(notification : NSNotification) {
// code to respond to notification
}
回答1:
I think the way you registered observer is not correct. Please try the below and check.
NotificationCenter.default.addObserver(self, selector:#selector(self.calendarDayDidChange(notification:)), name:NSNotification.Name.NSCalendarDayChanged, object:nil)
来源:https://stackoverflow.com/questions/45380920/notificationcenter-registered-selector-is-not-called