我自己找到了答案,即通过如下所述只写一个带有闭包的侦听器:
let net = NetworkReachabilityManager()net?.listener = { status in if net?.isReachable ?? false { switch status { case .reachable(.ethernetOrWiFi): print("The network is reachable over the WiFi connection") case .reachable(.wwan): print("The network is reachable over the WWAN connection") case .notReachable: print("The network is not reachable") case .unknown : print("It is unknown whether the network is reachable") }}net?.startListening()


