import Foundation
import Reachability
class CMNetworkManager: NSObject {
let reachability = try! Reachability()
override init() {
super.init()
}
class func isReachable() -> Bool {
// deprecated
// return self.sharedInstance.reachability.isReachable
return reachability.connection != .none
}
class func isReachableViaWifi() -> Bool {
//deprecated
//return self.sharedInstance.reachability.isReachableViaWiFi
return reachability.connection == .wifi
}
class func isReachableViaWWAN() -> Bool {
// deprecated
// return self.sharedInstance.reachability.isReachableViaWWAN
return reachability.connection == .cellular
}
class func testCodeFromDocumentation () {
reachability.whenReachable = { reachability in
if reachability.connection == .wifi {
print("Reachable via WiFi")
} else {
print("Reachable via Cellular")
}
}
reachability.whenUnreachable = { _ in
print("Not reachable")
}
do {
try reachability.startNotifier()
} catch {
print("Unable to start notifier")
}
}
}
Whenever reachability.something
is used this error shows up in Xcode:
Instance member 'reachability' cannot be used on type 'CMNetworkManager'
NOTE:
The answers mentioned here do not apply to my example. ( make sure you're not attempting to modify the class rather than the instance). I am modifying an instance here (reachability)