//类 class Student: NSObject{ //存储属性: var age :Int=0 var name:String? var mathscore:Double=0.0 var chinesescore:Double=0.0 //计算属性; 平均成绩 var averageScroe:Double{ return(mathscore+chinesescore)/2; } //定义类属性:类属性是和整个类相关的属性,而且是通过类名进行访问的 static var courseCount:Int=0 } //给类属性进行赋值 Student.courseCount=2; //创建对象 let p=Student() //对象属性赋值 p.age=10 p.name="哈哈" p.mathscore=99.1 p.chinesescore=34.2 print(p.averageScroe)