title: Create a socket in Swift
body: <p>I'm trying to write a simple echo server with swift. The examples I found are either <a href="https://gist.github.com/satoshiam/65f74106f5c69697314f" rel="nofollow">non-functional and low-level</a> or <a href="https://developer.apple.com/library/mac/samplecode/CocoaEcho/Introduction/Intro.html" rel="nofollow">written in objective-c</a>.</p>
  
  <p>I failed at a lot of things, I will start from the top. I cannot manage to create a simple socket using higher-level functions like <code>CFSocketCreate</code>. This is what I ended up with:</p>
  
  <pre><code>class EchoServer : NSObject, NSStreamDelegate
  {
      private var serverSocket: CFSocketRef?
  
      func start()
      {
          self.serverSocket = CFSocketCreate(kCFAllocatorDefault, AF_INET, SOCK_STREAM, 0, 2, &amp;self.acceptConnection, NSNull())
      }
  
      func acceptConnection(socket: CFSocketRef, type: CFSocketCallBackType, address: CFDataRef, data: UnsafePointer&lt;Void&gt;, info: UnsafeMutablePointer&lt;Void&gt;)
      {
          // Accept connection and stuff later
      }
  }
  </code></pre>
  
  <p>I am new to xcode/objectivec/swift and I'm having a hard time even understanding the error message. The above code leaves me simply with</p>
  
  <blockquote>
    <p>EchoServer.swift:31:93: '(CFSocketRef, type: CFSocketCallBackType, address: CFDataRef, data: UnsafePointer, info: UnsafeMutablePointer) -> ()' is not convertible to '@lvalue inout $T10'</p>
  </blockquote>
  
  <p>I'm not even able to make head or tail of this.</p>