Swift:声明'description'不能覆盖多个超类声明 [英] Swift: declaration 'description' cannot override more than one superclass declaration

查看:702
本文介绍了Swift:声明'description'不能覆盖多个超类声明的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个类似于下面的继承结构。我采用可打印协议,并严格重写描述属性。我遇到了一个奇怪的错误,谷歌在这一点上似乎是未知的,提示为第三类,并引用第二和第一类。

I have a structure of inheritance similar to the one below. I'm adopting the Printable protocol and diligently override description property. I have encountered a bizarre error that seems to be unknown to Google at this point in time, that is prompted for the Third class, and references Second and First class.

添加侮辱伤害,下面的代码实际上编译罚款,但我的完整代码不。评论属性第二和第三解决问题和代码编译,测试通过等。

To add insult to injury, the code below actually compiles fine, but my full code does not. Commenting the properties out on Second and Third solves the problem and the code compiles, tests pass etc.

Swift继承章提供了这个指针。

Swift inheritance chapter provides pointers to this.

有人知道这是什么意思和什么情况触发它吗?

Does anyone know what it means and which circumstances trigger it?


/Users/ivanhoe/Dropbox/swift/convergence/Processable.swift:124:18:
错误:声明的说明'不能覆盖多个
超类声明
override var description:String {
^ /Users/ivanhoe/Dropbox/swift/convergence/Processable.swift:85:18:
注意:重写的声明在这里
override var description:String {
^ /Users/ivanhoe/Dropbox/swift/convergence/Processable.swift:28:18:
注意:覆盖的声明在这里
override var description:String {

/Users/ivanhoe/Dropbox/swift/convergence/Processable.swift:124:18: error: declaration 'description' cannot override more than one superclass declaration override var description : String { ^ /Users/ivanhoe/Dropbox/swift/convergence/Processable.swift:85:18: note: overridden declaration is here override var description : String { ^ /Users/ivanhoe/Dropbox/swift/convergence/Processable.swift:28:18: note: overridden declaration is here override var description : String {



import Foundation

class First : NSObject, Printable {

    override var description : String {
        return "first"
    }
}

class Second : First {

    override var description : String {
        return "second"
    }

}

class Third : Second {

    override var description : String {
        return "third"
    }

}

println(Third())


推荐答案

func customDescription() -> String {
    return ""
}

override var description: String {
    return customDescription()
}

,以便您可以覆盖函数

这篇关于Swift:声明'description'不能覆盖多个超类声明的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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