在Swift 3 NotificationCenter观察器中使用选择器

在Swift 3 NotificationCenter观察器中使用选择器

问题描述:

NotificationCenter.default.addObserver(self, selector: Selector(("uploaded")), name: NSNotification.Name(rawValue: "uploaded"), object: nil)

我正在写名字:已上传:并且xcode将其更正为上述代码。问题是当运行应用程序我得到无法识别的选择器。

I was writing name: "uploaded:" and xcode corrected it to the above code. The problem is when running the app i get unrecognized selector.

任何人都知道如何修复它以使用swift 3

Any one know how to fix this to work with swift 3

NotificationCenter.default.addObserver(self, selector: #selector(ViewController.update), name: NSNotification.Name(rawValue: "uploaded"), object: nil)

func update() {
      // do what you want
   }

请注意,ViewController是您的函数

please note that "ViewController" is the class name where your function is