我在Objective C文件中有一个通知观察者,我想在Swift 3文件中触发通知。因为在Objective C中,通知名称是NSString,但在Swift 3中它是Notification.Name,我怎样才能让Obj-C观察者捕获Swift火?
Swift Trigger
NotificationCenter.default.post(name: .notificationName, object: nil, userInfo: nil)
extension Notification.Name {
static let notificationName = Notification.Name("Test")
}
Obj-C Observer
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(displayError:)
name:"Test"
object:nil];
答案 0 :(得分:-1)
你会触发这样的通知:
NotificationCenter.default.post(
name: Notification.Name(rawValue: "SomeNotification"),
object: nil,
userInfo: nil
)