我正在尝试将SCNetworkReachabilitySetCallback
的第二个参数称为SCNetworkReachabilityCallBack
在Swiftified SCNetworkReachability.h
中,这被定义为:
typealias SCNetworkReachabilityCallBack = CFunctionPointer<((SCNetworkReachability!, SCNetworkReachabilityFlags, UnsafeMutablePointer<Void>) -> Void)>
在Objective-C中,我声明了一个类似的函数:
static void MYReachabilityCallback(SCNetworkReachabilityRef target, SCNetworkReachabilityFlags flags, void* info) {
// do something
}
并将其作为参数传递。我是Swift似乎我应该传递一个带有SCNetworkReachabilityCallBack
中定义的签名的闭包,类似这样:
let callback = { (target: SCNetworkReachability!, flags: SCNetworkReachabilityFlags, info: UnsafeMutablePointer<Void>) in
// Do something
}
但这会产生错误:
无法转换表达式的类型'(SCNetworkReachability!, SCNetworkReachabilityFlags,UnsafeMutablePointer) - &gt; (SCNetworkReachability !, SCNetworkReachabilityFlags, UnsafeMutablePointer) - &gt; $ T0'输入'(SCNetworkReachability!, SCNetworkReachabilityFlags,UnsafeMutablePointer) - &gt; (SCNetworkReachability !, SCNetworkReachabilityFlags, UnsafeMutablePointer) - &gt; $ T0'
有点令人费解!
是否有其他人遇到此问题或有解决方案?
答案 0 :(得分:-5)
static void MYReachabilityCallback(SCNetworkReachabilityRef target, SCNetworkReachabilityFlags flags, void* info) {
// do something
}