协议定义为“NotificationCenter”对象?

时间:2017-07-19 20:42:34

标签: swift nsnotificationcenter

我有一个协议定义:

protocol Environment {
  var url: String {get}
}

我将它作为对象提供给NotificationCenter

NotificationCenter.default.post(name: NotificationForEnvironmentChange, object: Environment)

但它没有显示在我为NotificationForEnvironmentChange选择器分配的函数的object属性中。

func environmentChange(sender: Notification) {
    guard let newEnvironment = sender.object as? Environment else {
        return
    }
    //Never gets the environment
}

为什么?

注意:NotificationForEnvironmentChange是我定义的Notification属性,如下所示:

let NotificationForEnvironmentChange = Notification.Name("NotificationForEnvironmentChange")

0 个答案:

没有答案
相关问题