SmoothOperator SmoothOperator - 2 months ago 14
iOS Question

Swift 3 error when using didPressRightButton() (SlackTextViewController)

I am trying to implement

didPressRightButton()
from
SlackTextViewController
using the following code and it is giving me an error since migrating to
Swift 3
using
Xcode 8
.

override func didPressRightButton(sender: AnyObject?) {

if let messageToSend = self.textInputbar.textView.text {

// Save messageToSend to db
self.textInputbar.textView.text = ""
super.didPressRightButton(sender)
}
}


The Error that I'm now getting is,


Method does not override any method from its superclass.


I'm not sure why this appeared since
Swift 3
, Thanks in advance.

Answer

You get this error since upgrading to Swift 3 because SlackTextViewController is written in Objective-C.

Since Swift 3, the Objective-C type id is now imported as Any not AnyObject.

So when you are calling super.didPressRightButton(sender) with a sender of type AnyObject, Swift compiler can't find the method you are referring to.

Fix: Just change AnyObject to Any in your method definition. (Not sure if optionality is needed though…)