A very simple example of iOS Swift inheritance with the copy constructor. When I try to compile this, Xcode complains that I'm overriding a function that was defined with the parameter type Base and in child it's Child.
I agree with the compiler that the type is different but still he should let me do it somehow without using a different function name...
import Foundation
import SpriteKit
class Base : SKSpriteNode
{
private var a : Int = 0
init(other: Base)
{
self.a = other.a
super.init(fileNamed: "test")
}
required init?(coder aDecoder: NSCoder)
{
fatalError("init(coder:) has not been implemented")
}
}
class Child : Base
{
private var b : Int = 0
init(other: Child)
{
self.b = other.b
super.init(other: other)
}
required init?(coder aDecoder: NSCoder)
{
fatalError("init(coder:) has not been implemented")
}
}
So is there a way of doing this in Xcode 6 and Swift please? Cheers, TK
Edit: Unfortunately I wrote my question so that it's easily misunderstood. So it's really only about the copy constructor and nothing else. Adjusted the code from a simple pseudo code to actual code that does not compile because of the mentioned problem.