1

我在Objective C文件中有一個通知觀察者,我想在Swift 3文件中啓動通知。由於在Objective C中,通知名稱是一個NSString,但在Swift 3中它是Notification.Name,我怎樣才能讓Obj-C觀察者捕捉Swift火焰?如何在Objective-C中添加觀察者並在Swift中啓動通知3

斯威夫特觸發

NotificationCenter.default.post(name: .notificationName, object: nil, userInfo: nil) 

extension Notification.Name { 
    static let notificationName = Notification.Name("Test") 
} 

的OBJ-C觀察

[[NSNotificationCenter defaultCenter] addObserver:self 
             selector:@selector(displayError:) 
             name:"Test" 
             object:nil]; 

回答

-1

你會引發這樣的通知:

NotificationCenter.default.post(
    name: Notification.Name(rawValue: "SomeNotification"), 
    object: nil, 
    userInfo: nil 
) 
+0

觀察員是一個目標C文件雖然 – Schuey999

+0

應工作:)...只是無視我答案的聽力部分。 – Jan

+0

NSNotification在Objective C中沒有名稱屬性。我對觸發器沒有任何問題。我只是不能讓觀察者趕上它 – Schuey999

相關問題