I recently upgraded from AFNetworking 4 to 5.
This was the old way of initializing the listener:
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()
The new documentation reads this:
@discardableResult
open func startListening(onQueue queue: DispatchQueue = .main,
onUpdatePerforming listener: @escaping Listener) -> Bool
https://alamofire.github.io/Alamofire/Classes/NetworkReachabilityManager.html
In my code, I am trying this:
let listener = NetworkReachabilityManager.Listener()
self.reachabilityManager?.startListening(onUpdatePerforming: listener){
}
The compilation error I am getting is Extra argument 'onUpdatePerforming' in call. It is a syntactical issue, I am transitioning form Objective C to Swift.
What I attempt to pass a closure, I also cannot seem to get the syntax correct:
self.reachabilityManager?.startListening(onUpdatePerforming: { (NetworkReachabilityManager.Listener) in
})