你知道出了什么问题吗? 我只想打印一个类的变量。 我认为打印必须在方法内部,但我不知 Prop 体如何。
import UIKit
class Class {
var name: String
init(name:String){
self.name
}
class Subclass : Class {
var level: Int
init(name:String, level:Int){
self.level
super.init(name: name)
}
}
var subclass1 = Subclass(name: "Hallo", level: 10)
print(subclass1.level) // <-- here I get the error "Expected Declaration"
最佳答案
我对 Swift 不太熟悉,但看起来你缺少 init.h 中的声明。
...
self.name = name
...
和
...
self.level = level
...
希望有帮助。
代码中还缺少一个大括号。
class Class {
...
init(...) {
...
->}//missing
}
关于swift - 在 Swift 中打印类变量 - 预期声明错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33243509/