【问题标题】:NSNotificationCenter SyntaxNSNotificationCenter 语法
【发布时间】:2020-10-03 13:48:34
【问题描述】:

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

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

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

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

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

【问题讨论】:

    标签: ios swift xcode nsnotificationcenter


    【解决方案1】:

    您必须导入NotificationCenter,它将是:

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

    【讨论】:

    • 导入 MultipeerConnectivity 是否也会导入 NotificationCenter....... 因为我可以在 DispatchQueue.main.async 中编写代码而不导入 NotificationCenter?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-04-26
    • 2014-07-25
    相关资源
    最近更新 更多