title: Toll-free bridging and pointer access in Swift
body: <p>I am porting an App from Objective-C to Swift and I need to use the following method:</p>
  
  <pre><code>CFStreamCreatePairWithSocketToHost(alloc: CFAllocator!, host: CFString!, port: UInt32, \
  readStream: CMutablePointer&lt;Unmanaged&lt;CFReadStream&gt;?&gt;, \
  writeStream: CMutablePointer&lt;Unmanaged&lt;CFWriteStream&gt;?&gt;)
  </code></pre>
  
  <p>The old logic looks like this (which several web sites seem to agree on):</p>
  
  <pre><code>CFReadStreamRef readStream = NULL;
  CFWriteStreamRef writeStream = NULL;
  CFStreamCreatePairWithSocketToHost(NULL, (__bridge CFStringRef)(host), port, \
                                     &amp;readStream, &amp;writeStream);
  
  NSInputStream inputStream = (__bridge_transfer NSInputStream *)readStream;
  NSOutputStream outputStream = (__bridge_transfer NSOutputStream *)writeStream;
  </code></pre>
  
  <p>Which works fine thanks to toll-free bridging. However, ARC does not exist in "Swift-space", and the type system has changed.</p>
  
  <p>How do I turn my streams into instances of</p>
  
  <pre><code>CMutablePointer&lt;Unmanaged&lt;CFReadStream&gt;?&gt;, and
  CMutablePointer&lt;Unmanaged&lt;CFWriteStream&gt;?&gt;
  </code></pre>
  
  <p>And then convert them back into <code>NSStream</code> subclasses after the <code>CFStreamCreatePairWithSocketToHost</code> call?</p>