title: CFStreamCreatePairWithSocketToHost crashes unexpectedly with Swift
body: <p>Finally time to ask my first question here!</p>
  
  <p>Up front: Xcode 7.1.1, OS 10.11.2, iOS 9.0.2 (on physical device)</p>
  
  <p>I'm writing a small app that communicates with my Raspberry Pi. I've got some working code that's written in Obj-C (for iOS 7) borrowed from a <a href="http://bitcows.com/?p=249" rel="nofollow noreferrer">tutorial</a>, and it all works fine for me in Obj-C (connects and behaves as expected with the Pi). The issue lies with rewriting it for Swift/iOS 9 (which is the goal).</p>
  
  <p>The good bit:</p>
  
  <pre><code>func initNetworkCommunication() {
      var readStream: Unmanaged&lt;CFReadStreamRef&gt;?
      var writeStream: Unmanaged&lt;CFWriteStreamRef&gt;?
  
      CFStreamCreatePairWithSocketToHost(nil, "192.168.1.22", 777, &amp;readStream, &amp;writeStream)
  
      inputStream = readStream?.takeRetainedValue() as! NSInputStream
      outputStream = writeStream?.takeRetainedValue() as! NSOutputStream
  
      inputStream.scheduleInRunLoop(NSRunLoop.currentRunLoop(), forMode: NSDefaultRunLoopMode)
      outputStream.scheduleInRunLoop(NSRunLoop.currentRunLoop(), forMode: NSDefaultRunLoopMode)
  
      inputStream.open()
      outputStream.open()
  }
  </code></pre>
  
  <p>I believe the issue to lie in the above as this is the last method call in the stack, however the application crashes quietly with little information:</p>
  
  <p><a href="https://i.stack.imgur.com/wsuAC.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/wsuAC.jpg" alt="Crash Screen"></a></p>
  
  <p>Any help would be much appreciated!<br>
  Please feel free to ask for more information.</p>
  
  <p>p.s. I understand the formatting on this site is rather "strict", anything I missed, overdid, etc, please let me know :)</p>