gpt4 book ai didi

swift - print() 的长参数产生错误 "Expression was too complex to be solved"

转载 作者:搜寻专家 更新时间:2023-11-01 07:06:42 25 4
gpt4 key购买 nike

我是 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))

关于swift - print() 的长参数产生错误 "Expression was too complex to be solved",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47610398/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com