感觉swift的结构体和类有点相似
// 定义结构体 struct Student { var name: String var age: Int var height: Float? // 可选型在构造函数中可以不必初始化 init(name: String,age: Int) { self.name = name self.age = age } init(name: String,age: Int,height:Float) { self.name = name self.age = age self.height = height } } // 实例化 var stu = Student(name: "gaobo",age: 24) var stu1 = Student(name: "gaoxiaobo",age: 23,height: 1.8)原文链接:https://www.f2er.com/swift/322160.html