1,init():类的初始化方法(构造方法)
class Student: NSObject { //类属性 var name:String = "" var age:Int = 0 //类构造函数 init(newName:String,newAge:Int){ self.name = newName self.age = newAge } //成员函数 func run() -> String { return "\(name) can run" } } var student = Student(newName:"baibai",newAge:31) student.name = "张三" print(student.name) print(student.age) print(student.run())
原文地址:https://www.cnblogs.com/baidaye/p/8631630.html
时间: 2024-10-09 11:42:02