title: How to convert NSStream (NSInputStream / NSOutputStream) to SSL after stream opened?
body: <p>I have NSInputStream and NSOutputStream from this code </p>
  
  <pre><code>    var readStream: Unmanaged&lt;CFReadStream&gt;?
      var writeStream: Unmanaged&lt;CFWriteStream&gt;?
  
      CFStreamCreatePairWithSocket(kCFAllocatorDefault, sslSocket!, &amp;readStream, &amp;writeStream)
      if readStream != nil &amp;&amp; writeStream != nil {
          CFReadStreamSetProperty(readStream!.takeUnretainedValue(), kCFStreamPropertyShouldCloseNativeSocket, kCFBooleanTrue)
          CFWriteStreamSetProperty(writeStream!.takeUnretainedValue(), kCFStreamPropertyShouldCloseNativeSocket, kCFBooleanTrue)
  
          inputStream = readStream!.takeRetainedValue()
          outputStream = writeStream!.takeRetainedValue()
  
          // Create strong delegate reference to stop ARC deallocating the object
          inputDelegate = self
          outputDelegate = self
  
          // Now that we have a strong reference, assign the object to the stream delegates
          inputStream!.delegate = inputDelegate
          outputStream!.delegate = outputDelegate
  
  
          // Schedule our run loops. This is needed so that we can recieve NSStreamEvents
          inputStream!.scheduleInRunLoop(NSRunLoop.mainRunLoop(), forMode: NSDefaultRunLoopMode)
          outputStream!.scheduleInRunLoop(NSRunLoop.mainRunLoop(), forMode: NSDefaultRunLoopMode)
  
          inputStream!.open()
          outputStream!.open()
      }
  </code></pre>
  
  <p><strong>Issue</strong>: How do I convert those stream to SSL after it was opened ?</p>
  
  <p>I <strong>tried</strong> following, but I get <code>NSOSStatusErrorDomain</code>: </p>
  
  <blockquote>
    <p>The operation couldn't be completed. (OSStatus error -9801)</p>
  </blockquote>
  
  <pre><code>if (sslEnable) {
      let sslSettings = [
          NSString(format: kCFStreamSSLValidatesCertificateChain): kCFBooleanFalse,
          NSString(format: kCFStreamSSLPeerName): kCFNull,
          NSString(format: kCFStreamSSLIsServer): kCFBooleanTrue,
      ]
      CFReadStreamSetProperty(inputStream, kCFStreamPropertySSLSettings, sslSettings)
      CFWriteStreamSetProperty(outputStream, kCFStreamPropertySSLSettings, sslSettings)
  
  }
  </code></pre>