Wenn ich den folgenden Code verwenden:Mitteilung addObserver nicht mit Standard-Weise reagiert
override func viewDidLoad() {
nc = NotificationCenter.default
nc.addObserver(self, selector: #selector(self.receivedNotification), name:MyNotification, object: nil)
}
func receivedNotification() -> void {
NSLog("notification received")
}
receivedNotification
nie
genannt Aber wenn ich die folgende Schließung Weise
verwendennc.default.addObserver(forName:MyNotification, object:nil, queue:nil) {
notification in
NSLog("notification received")
}
NSLog("...")
ist erfolgreich namens.
Kann mir bitte jemand erklären, was hier geschieht
NSNotificationCenter verwenden können. defaultCenter(). postNotificationName ("MyNotification", Objekt: nil) –
self.receivedNotification sollte NameOfClass.receivedNotification sein – jarryd