ivanhoe1982 ivanhoe1982 - 7 months ago 15
Swift Question

Swift: declaration 'description' cannot override more than one superclass declaration

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 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:
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())

Answer

Same problem for me, solved by doing:

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

override var description: String {
    return customDescription()
}

so you can override function as many times as you want to

Comments