Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Swift protocols: method does not override any method from its superclass

Since Xcode 6 still has a lots of bugs with Swift, I'm not sure is it one or I'm missing something. My class adopts protocol NSLayoutManagerDelegate. But it seems impossible to override method I need. I do as documentation describes:

override func layoutManager(_ aLayoutManager: NSLayoutManager!,         didCompleteLayoutForTextContainer aTextContainer: NSTextContainer!,         atEnd flag: Bool) {      } 

But I get error here: method does not override any method from its superclass. What should I do?

like image 883
Vitalii Vashchenko Avatar asked Jun 24 '14 07:06

Vitalii Vashchenko


People also ask

What is an override function in Swift?

Swift version: 5.6. The override is used when you want to write your own method to replace an existing one in a parent class. It's used commonly when you're working with UIViewControllers , because view controllers already come with lots of methods like viewDidLoad() and viewWillAppear() .

How to prevent inheritance in Swift?

You can prevent a method, property, or subscript from being overridden by marking it as final. Do this by writing the final modifier before the method, property, or subscript's introducer keyword (such as final var , final func , final class func , and final subscript ).


1 Answers

You're implementing a method from the protocol, yes, but it's not an override. Just remove the override keyword. An override is when your superclass also implements that method and you're providing a version that replaces or modifies the behavior of the superclass implementation. That's not what's happening here.

like image 158
Ken Thomases Avatar answered Sep 22 '22 11:09

Ken Thomases