error: initializer does not override a designated initializer from its superclass

swift for clion have problem "error: initializer does not override a designated initializer from its superclass"

Do you have any solution to my problem

main.swift

public class HelloSwift: MyClass {
override init(text: String) {
super.init (text: text)
}

convenience init() {
self.init (text: "Hello Swift!")
}

func greet(persons: [String:String]) {
for (name, location) in persons {
print("Hello \(name)")
print("I hope the weather is nice in \(location)")
}
}
}

//HelloSwift().sayHello()
let start = HelloSwift()
start.seyHello()
let team = ["Pratumma","Yuranun","Pratumpan"]
start.greet(team)

MyClass.swift

public class MyClass {
public var text: String

init(text: String) {
self.text = text

}
func sayHello() {
print(text)
}
}
1 comment
Comment actions Permalink

Hello!

Could you please clarify where you are seeing this error? Is it printed in the build output, or highlighted in yellow within the source editor?

I can't reproduce the issue on my side: the class hierarchy compiles without any errors, and no errors are shown in the editor. The error you're seeing is coming from either the Swift compiler or SourceKit. Could you please try updating the Swift toolchain to a newer version?

0

Please sign in to leave a comment.