Xcode Swift не может получать уведомления от Object- C - PullRequest
0 голосов
/ 14 февраля 2020

Я использую NetworkSpeedMonitor для проверки пользовательских сетей. Это мой код

networking = NetworkSpeedMonitor()
networking.start()
NotificationCenter.default.addObserver(self, selector: #selector(networkSpeedChanged(_:)), name: NSNotification.Name(rawValue: NetworkDownloadSpeedNotificationKey), object: self)

Это моя функция селектора

@objc func networkSpeedChanged(_ notification:NSNotification) {
    // never run
    if let downloadSpeed = notification.userInfo?[NetworkSpeedNotificationKey] as? String {
        self.networkingLabel.text = downloadSpeed
    }    
}

, но я считаю, что селектор не работает

1 Ответ

0 голосов
/ 14 февраля 2020

NotificationCenter.default.addObserver (self, селектор: #selector (networkSpeedChanged (_ :)), имя: NSNotification.Name (rawValue: NetworkDownloadSpeedNotificationKey), объект: nil)

вместо

NotificationCenter.default.addObserver (self, селектор: #selector (networkSpeedChanged (_ :)), имя: NSNotification.Name (rawValue: NetworkDownloadSpeedNotificationKey), объект: self)

...