If I have a method like:
func someMethod(contextPtr: UnsafeMutablePointer<Void>)
how do I get the object from the contextPtr
?
func someMethod(contextPtr: UnsafeMutablePointer<Void>){
let object:MyObject = contextPtr.memory
}
gives:
'Void' is not convertible to 'MyObject'
What's the secret sauce
More detail:
What I'm actually doing here is setting up a global callback function for SCNetworkReachability
:
func callback(reachability:SCNetworkReachability, flags: SCNetworkReachabilityFlags, info: UnsafeMutablePointer<Void>) {
let r:Reachability = info.memory
}
and then adding the callback as follows:
var context = SCNetworkReachabilityContext(version: 0, info: nil, retain: nil, release: nil, copyDescription: nil)
var s = self
withUnsafeMutablePointer(&s) {
context.info = UnsafeMutablePointer($0)
}
SCNetworkReachabilitySetCallback(reachability, callback, &context)