Using selector in Swift 3 NotificationCenter obser

2019-03-03 20:34发布

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

2条回答
ゆ 、 Hurt°
2楼-- · 2019-03-03 21:14
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

查看更多
时光不老,我们不散
3楼-- · 2019-03-03 21:27

Use the (identifier checking) #selector syntax:

Without parameter:

#selector(uploaded)

With parameter:

#selector(uploaded(_:))
查看更多
登录 后发表回答