Using selector in Swift 3 NotificationCenter observer

后端 未结 2 1367
慢半拍i
慢半拍i 2021-01-23 10:43
NotificationCenter.default.addObserver(self, selector: Selector((\"uploaded\")), name: NSNotification.Name(rawValue: \"uploaded\"), object: nil)

I was

2条回答
  •  迷失自我
    2021-01-23 11:12

    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

提交回复
热议问题