打印()的长参数会产生错误“表达式太复杂而无法解决”

我是新的Swift,当我想要构建此代码时遇到问题。 “表达太复杂,无法在合理的时间内解决;考虑将表达分解为不同的子表达式”。打印()的长参数会产生错误“表达式太复杂而无法解决”

我想我的方法来管理属性,当我想打印的东西是错误的,但我没有找到原因。

class Personne{ 

var name : String

var forename : String

init(name : String, forename:String) {

self.name = name

self.forename = forename

}

}

class UnilStudent : Personne{

var id : Int

var section : String

init(name :String, forename:String, id:Int, section:String) {

self.section = section

self.id = id

super.init(name:name, forename:forename)

}

func affiche() {

print("Unil student N°" + \(self.id) + " : " + \(self.name) + \(self.forename) + "\n" + \(self.section + "\n")}

}

class Assistants : UnilStudent{

var assistantship : String

init(name :String, forename:String, id:Int, section:String, assistantship : String){

self.assistantship = assistantship

super.init(name :name, forename:forename, id:id, section:section)

}

override func affiche() {

super.affiche()

print("Unil student N°" + \(self.id) + " : " + \(self.name) + " " + \(self.forename) + "\n from " + \(self.section) + "is a student assistant for" + \(self.assistantship) + "\n")}

func printid(){

print("L'id de " + \(self.name) + " " + \(self.forename) + " est " + \(self.id))

}

}

let Adrien = Assistants(name : "BOB", forename : "BOBBY", id : 12000000, section : "FDCA", assistantship : "ACT")

let Alice = UnilStudent(name: "Hapoka", forename : "Alice", id : 17000000, section : "HEC")

print(Adrien)

回答:

该问题与继承无关。 \(...)串内插和只能用于内部一个字符串,例如:

print("Unil student N°\(self.id) : \(self.name)\(self.forename)") 

代替

print("Unil student N°" + \(self.id) + " : " + \(self.name) + \(self.forename)) 

以上是 打印()的长参数会产生错误“表达式太复杂而无法解决” 的全部内容, 来源链接: utcz.com/qa/257444.html

回到顶部