Delegating Objective-C Protocol on Swift
delegates, ios, objective-c, swift
Solution
`override` keyword is for overriding methods of superclass. As you are not overriding any methods, `override` keyword is not needed.
Problem
I'm implementing an UDP Listener on iOS using the Swift language. For this I'm relaying on the CocoaAsyncSocket project. 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. This is the code where I set the Socket and define the ViewController.swif as the delegate class for the listener: ``` 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: &error) udpSocket.joinMulticastGroup(address, error: &error) udpSocket.enableBroadcast(true, error: &error) println("228.5.12.12") } ``` This is the former delegate function in Objective-C: ``` - (void)udpSocket:(GCDAsyncUdpSocket *)sock didReceiveData:(NSData *)data fromAddress:(NSData *)address withFilterContext:(id)filterContext; ``` And finally, this is how I'm implementing the function on Swift: ``` override func udpSocket(sock : GCDAsyncUdpSocket!, didReceiveData data : NSData!, fromAddress address : NSData!, withFilterContext filterContext : AnyObject!) { println(data) } ``` ViewController class is declared to implement the right protocol: ``` class ViewController: UIViewController, GCDAsyncUdpSocketDelegate { ... } ``` I got no compile error except for the override. Question: What am I doing wrong?