1

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?

Ashley Mills
  • 50,474
  • 16
  • 129
  • 160
  • 2
    This is currently not supported, see http://stackoverflow.com/questions/25057161/how-to-use-the-coreaudio-api-in-swift for a similar issue. I think this restriction still applies to beta 7. – Martin R Sep 04 '14 at 07:50

1 Answers1

-5
static void MYReachabilityCallback(SCNetworkReachabilityRef target, SCNetworkReachabilityFlags flags, void* info) {
        // do something
}
benka
  • 4,732
  • 35
  • 47
  • 58