I am learning swift on my own but I cannot manage to make this code run, I am trying to create a class "Inhabitant" inheriting from Person class with a new "Country" property, have 2 initializers: - one that takes firstname and lastname and sets the country to an empty String - one that takes firstname, lastname and country and create a computed property description of String type that return a the firstname, lastname and country separated by a space
class Person {
var firstname: String
var lastname: String
var fullname: String {
return firstname + " " + lastname
}
init(firstname: String, lastname: String) {
self.firstname = firstname
self.lastname = lastname
}
}
class Inhabitant: Person {
var country: String? = nil
var description: String {
return firstname + " " + lastname + " " + country ?? ""
}
override init(firstname: String, lastname: String) {
super.init(firstname: <#T##String#>, lastname: <#T##String#>)
self.country = ""
}
init(firstname: String, lastname: String, Country: String) {
super.init(firstname: <#T##String#>, lastname: <#T##String#>)
}
}
func tst() {
let perso = Inhabitant(firstname: "toto", lastname: "bobo")
print(perso)
}
The code won't run:
Editor placeholder in source file
<#T##String#>to some String. The easy way is select it and type if it is still a "live" placeholder; otherwise you'll just have to do it by hand. Learn about Xcode's "autocomplete" feature. What you want arefirstnameandlastnamehere. In other words, you just want to pass the incomingfirstnameandlastnamevalues up the inheritance chain to thesuper.initcall. - mattStringaftersuper.init(firstname:? That's an "editor placeholder". You need to replace that with something. - Sweepersuper.init(firstname: firstname, lastname: lastname)- clawesome