【问题标题】:How do I access the Notification (foundation class) and not my (custom class named Notification)?如何访问 Notification(基础类)而不是我的(名为 Notification 的自定义类)?
【发布时间】:2019-10-12 07:11:59
【问题描述】:

问题是,我想在我的扩展文件上创建一个扩展,如下所示。

extension Notification.Name {
    static let value = Notification.Name(rawValue: "value")
}

但不幸的是,它正在读取我名为 Notification 的自定义类,而我这次只想直接访问基础...所以我可以去 .Name

除了方法之外,还有像@DoNotReadCustomClass 这样的android 中提到的方法吗?哈哈之类的?

@onlyGoForFundationClass? @exeptionForThisTimeOnCustomClass 或类似的东西?

谢谢。

【问题讨论】:

  • 重命名您的自定义类。 覆盖系统结构/类是不好的做法
  • 好建议!谢谢。赞赏!

标签: ios swift observers


【解决方案1】:

您可以在它前面加上声明类的模块名称。在这种情况下,它将是:

extension Foundation.Notification.Name {
    static let value = Foundation.Notification.Name(rawValue: "value")
}

【讨论】:

  • 非常感谢!我已经重命名了课程,但我不知道那个提示!赞赏!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-12-10
  • 1970-01-01
  • 2023-03-22
  • 1970-01-01
  • 2011-12-29
  • 1970-01-01
相关资源
最近更新 更多