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

查看:26
本文介绍了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天全站免登陆