Swift协议:方法不会覆盖其超类中的任何方法 [英] Swift protocols: method does not override any method from its superclass

查看:897
本文介绍了Swift协议:方法不会覆盖其超类中的任何方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于Xcode 6仍然有很多与Swift的错误,我不确定是一个还是我错过了一些东西。
我的类采用协议NSLayoutManagerDelegate。但是似乎不可能重写我需要的方法。我做文档描述:

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?

推荐答案

你正在从协议中实现一个方法,是的,覆盖。只需删除 override 关键字即可。覆盖是当你的超类也实现了这个方法,并且你提供了一个替换或修改超类实现的行为的版本。这不是这里发生的。

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.

这篇关于Swift协议:方法不会覆盖其超类中的任何方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆