如何创建firstPerson,它应该具有其他类的列表属性
导入UIKit 导入基金会
班级人物{ var age:Int 变量名称:字符串 var surname:String
init(age:Int, name:String, surname:String){
self.age=age
self.name=name
self.surname=surname
}
let Everyone = PersonBank()
let firstPerson = Everyone.list[0]
}
class PersonBank{
var list = [Person]()
init(){
list.append(Person(age: 25, name: "Brad", surname: "Hood"))
list.append(Person(age: 25, name: "Ryan", surname: "Milson"))
}
}
错误:
不能在属性初始化程序中使用实例成员“所有人”; 属性初始化程序在“自我”可用之前运行 让firstPerson = Everyone.list [0]