Reputation: 3361
Just started playing around with swift trying to write some code that detects if there is an internet connection. I am getting Could not find an overload for '!=' that accepts the supplied arguments on the last line. What am I doing wrong?
class func hasConnectivity() -> Bool {
let reachability: Reachability = Reachability.reachabilityForInternetConnection()
let networkStatus: NetworkStatus = reachability.currentReachabilityStatus()
return networkStatus != NotReachable
}
Upvotes: 1
Views: 267
Reputation: 64644
You can use the raw value of the enum:
class func hasConnectivity() -> Bool {
let reachability: Reachability = Reachability.reachabilityForInternetConnection()
let networkStatus: Int = reachability.currentReachabilityStatus().value
return networkStatus != 0
}
NotReachable
always has a value of 0 so you can check against that.
Upvotes: 1
Reputation: 2843
One way to return the result you are looking for would be to switch on networkStatus
:
switch networkStatus {
case .NotReachable:
return false
default:
return true
}
Upvotes: 1