问题
NotificationCenter.default.addObserver(self, selector: Selector(("uploaded")), name: NSNotification.Name(rawValue: "uploaded"), object: nil)
I was writing name: "uploaded:" and xcode corrected it to the above code. The problem is when running the app i get unrecognized selector.
Any one know how to fix this to work with swift 3
回答1:
NotificationCenter.default.addObserver(self, selector: #selector(ViewController.update), name: NSNotification.Name(rawValue: "uploaded"), object: nil)
func update() {
// do what you want
}
please note that "ViewController" is the class name where your function is
回答2:
Use the (identifier checking) #selector syntax:
Without parameter:
#selector(uploaded)
With parameter:
#selector(uploaded(_:))
来源:https://stackoverflow.com/questions/39984164/using-selector-in-swift-3-notificationcenter-observer