Swift 2 - UnsafeMutablePointer <Void>到对象
如果我有一个像这样的方法:
func someMethod(contextPtr: UnsafeMutablePointer<Void>)
我如何从中获取对象contextPtr
?
func someMethod(contextPtr: UnsafeMutablePointer<Void>){ let object:MyObject = contextPtr.memory}
得到:
'Void'不能转换为'MyObject'
什么是秘诀
更多详情:
我在这里做的是设置一个全局回调函数SCNetworkReachability
:
func callback(reachability:SCNetworkReachability, flags: SCNetworkReachabilityFlags, info: UnsafeMutablePointer<Void>) { let r:Reachability = info.memory}
然后添加回调如下:
var context = SCNetworkReachabilityContext(version: 0, info: nil, retain: nil, release: nil, copyDescription: nil)var s = selfwithUnsafeMutablePointer(&s) { context.info = UnsafeMutablePointer($0)}SCNetworkReachabilitySetCallback(reachability, callback, &context)
qq_遁去的一_1