I'm trying to call SCNetworkReachabilitySetCallback
the second parameter of which is SCNetworkReachabilityCallBack
In the Swiftified SCNetworkReachability.h
, this is defined as:
typealias SCNetworkReachabilityCallBack = CFunctionPointer<((SCNetworkReachability!, SCNetworkReachabilityFlags, UnsafeMutablePointer<Void>) -> Void)>
In Objective-C, I'd declare a function like:
static void MYReachabilityCallback(SCNetworkReachabilityRef target, SCNetworkReachabilityFlags flags, void* info) {
// do something
}
and pass this as a parameter. I'n Swift it seems that I should be passing a closure with the signature defined in SCNetworkReachabilityCallBack
, something like this:
let callback = { (target: SCNetworkReachability!, flags: SCNetworkReachabilityFlags, info: UnsafeMutablePointer<Void>) in
// Do something
}
but this gives the error:
Cannot convert the expression's type '(SCNetworkReachability!, SCNetworkReachabilityFlags, UnsafeMutablePointer) -> (SCNetworkReachability!, SCNetworkReachabilityFlags, UnsafeMutablePointer) -> $T0' to type '(SCNetworkReachability!, SCNetworkReachabilityFlags, UnsafeMutablePointer) -> (SCNetworkReachability!, SCNetworkReachabilityFlags, UnsafeMutablePointer) -> $T0'
which is somewhat puzzling!
Has anyone else come across this problem or has a solution?