在Swift 3 NotificationCenter观察器中使用选择器 [英] Using selector in Swift 3 NotificationCenter observer

查看:74
本文介绍了在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

这篇关于在Swift 3 NotificationCenter观察器中使用选择器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆