× {{alert.msg}} Never ask again
Get notified about new tutorials RECEIVE NEW TUTORIALS

Toll-free bridging and pointer access in Swift

Scott Davis
Feb 03, 2015
<p>I wasn't able to get the examples others have provided in this thread to work. Sure, they compiled, but they crashed as soon as the connection was open.</p> <p>However, I noticed in the WWDC 2014 discussions (and iOS 8 release notes) that there is a new method for initializing an NSStream for creating a bound pair of in/out streams.</p> <p>See below:</p> <pre><code>var inputStream: NSInputStream? var outputStream: NSOutputStream? NSStream.getStreamsToHostWithName("localhost", port: 1234, inputStream: &amp;inputStream, outputStream: &amp;outputStream) </code></pre> <p>This removes the need for the awkward CFStreamCreatePairWithSocketToHost call as well as removing the need for Unmanaged resources.</p> <p>This tip was originally posted on <a href="http://stackoverflow.com/questions/24028995/Toll-free%20bridging%20and%20pointer%20access%20in%20Swift/24539363">Stack Overflow</a>.</p>
comments powered by Disqus