user3210986
user3210986

Reputation: 221

Overriding methods in protocols - Method does not override any method from its parent protocol

I'm trying to do this:

protocol ProtoA: UITextViewDelegate {}
extension ProtoA {
    override func textViewDidBeginEditing(_ textView: UITextView) { print("hi") }
}

I get an error in reference to the method textViewDidBeginEditing: Method does not override any method from its parent protocol

The signatures appear to be exactly the same. I thought that maybe this has to do with UITextViewDelegate being @objc or something but other than that I'm really stumped.

Upvotes: 0

Views: 447

Answers (1)

mimo
mimo

Reputation: 262

You don't need/want the override keyword here. Removing it should resolve the error.

UITextViewDelegate doesn't have its own implementation for func textViewDidBeginEditing(_ textView: UITextView), so you aren't overriding anything. Think of it as adding details to a blueprint rather than replacing an existing component with a different one.

Upvotes: 1

Related Questions