类
import UIKit
class Student {
var name : String?
var age : Int = 0
var chineseScore : Double = 0
var mathScore : Double = 0
//计算属性 : 通过别的方式计算到结果的属性,称之为计算属性
var averageScore: Double {
return (chineseScore + mathScore) * 0.5
}
//类属性:是和整个类相关的属性,而且是通过类名进行访问
static var courseCount : Int = 0
}
var stu = Student()
//给对象的属性赋值
stu.name = "mark"
stu.age = 18
stu.mathScore = 44.0
stu.chineseScore = 89.00
//给类属性赋值
Student.courseCount = 2
if let name = stu.name {
print(name)
}
stu.averageScore
网友评论