Swift 3:NSNotification与通知

Boo*_*oon 5 swift3

在Swift 3中,Notificationvs 之间有什么区别NSNotification

具体来说,在Notification struct中,有一个ReferenceType类型NSNotification.ReferenceType是如何在这里使用的?

public struct Notification : ReferenceConvertible, Equatable, Hashable {

    public typealias ReferenceType = NSNotification
    ...
}
Run Code Online (Sandbox Code Playgroud)

Ale*_*ica 1

Notification是一个结构包装器NSNotification。您可以使用 来在两者之间建立桥梁as,这就是它的ReferenceConvertible作用。

  • @MobileMon 是的,尽管你通常应该更喜欢 Swift 中的非“NS”变体。 (3认同)