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