title: Delegating Objective-C Protocol on Swift
body: <p>I'm implementing an UDP Listener on iOS using the Swift language.</p>
  
  <p>For this I'm relaying on the <a href="https://github.com/robbiehanson/CocoaAsyncSocket" rel="nofollow">CocoaAsyncSocket</a> project.</p>
  
  <p>I was succeeded on importing the CocoaAsyncSocket library using a Bridging-Header.h, I could call the functions from the Objective-C classes, but I'm not able to write the delegate function on swift.</p>
  
  <p>This is the code where I set the Socket and define the ViewController.swif as the delegate class for the listener:</p>
  
  <pre><code>func setupSocket() {
      var udpSocket : GCDAsyncUdpSocket = GCDAsyncUdpSocket(delegate: self, delegateQueue: dispatch_get_main_queue())
      var error : NSError?
      let port : UInt16 = 12121
      let address : String = "228.5.12.12"
      udpSocket.bindToPort(port, error: &amp;error)
      udpSocket.joinMulticastGroup(address, error: &amp;error)
      udpSocket.enableBroadcast(true, error: &amp;error)
      println("228.5.12.12")
  }
  </code></pre>
  
  <p>This is the former delegate function in Objective-C:</p>
  
  <pre><code>- (void)udpSocket:(GCDAsyncUdpSocket *)sock didReceiveData:(NSData *)data
                                                 fromAddress:(NSData *)address
                                           withFilterContext:(id)filterContext;
  </code></pre>
  
  <p>And finally, this is how I'm implementing the function on Swift:</p>
  
  <pre><code>override func udpSocket(sock : GCDAsyncUdpSocket!, didReceiveData data : NSData!,  fromAddress address : NSData!,  withFilterContext filterContext : AnyObject!) {
      println(data)
  }
  </code></pre>
  
  <p>ViewController class is declared to implement the right protocol:</p>
  
  <pre><code>class ViewController: UIViewController, GCDAsyncUdpSocketDelegate {
      ...
  }
  </code></pre>
  
  <p>I got no compile error except for the override.</p>
  
  <p><strong>Question:</strong> What am I doing wrong?</p>