Swift protocols: method does not override any meth

2019-01-13 20:16发布

问题:

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?

回答1:

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.