首页 > 解决方案 > NSNotificationCenter 语法

问题描述

我有这行代码,但它是 swift 的旧版本,我听说语法已经改变。代码写在下面。在 Xcode 11 中讲述它的当前语法会很有帮助。

我也对这些变化进行了很多研究,但找不到任何东西

DispatchQueue.main.async 中的代码是较旧的代码,我需要更新的语法

语法(从旧版本开始)如下所示:

DispatchQueue.main.async {
    NSNotificationCenter.defaultCenter().postNotificationName(  The parameters of the code  )
}

标签: iosswiftxcodensnotificationcenter

解决方案


您必须导入NotificationCenter,它将是:

DispatchQueue.main.async {
        NotificationCenter.default.post(name: Name Here, object: nil or Any)
 }

推荐阅读