54

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?

Vitalii Vashchenko
  • 1,777
  • 1
  • 13
  • 23

1 Answers1

119

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.

Ken Thomases
  • 88,520
  • 7
  • 116
  • 154
  • 21
    It's not a dumb question, because Xcode 6 auto-completion put the "override" for us, causing the confusion :-) – Golden Thumb Nov 23 '14 at 16:15
  • 8
    This is a shame though, as it means there's no compile-time check that ensures you've got the signature right... – MattM May 06 '15 at 00:20
  • Yeah, I was thinking this is a bad thing, since there’s no compile-time check that the signature is correct. But, since in Swift all protocol methods are required, you will get some kind of compile-error if you haven’t implemented all required methods. – DouglasHeriot Dec 04 '15 at 08:23
  • @DouglasHeriot yes, but you do not get a warning if you implement methods defined in a protocol but don't implement the protocol itself. – Jeremy Sep 01 '16 at 14:33