/**
在进行类的定义时,可以定义三种属性:对象属性,计算属性,类属性
【1】 常量属性。 常量属性在对象被创建出来以后就不能再被修改
常量属性有三种属性:1.基本数据类型。2.结构体或者枚举等值类型实例。3.引用类型实例。
【2】常量属性的赋值方法。 要想设置常量属性的值。需要在初始化的时候进行。
【3】变量属性就是用来存储对象的属性值的,也可以在任何时候对任何对象的属性进行修改。
【4】懒加载。也叫延迟加载。lazy
【5】监听属性值的变化。属性监听也成为观察者模式。
【6】运算属性。运算属性并不是用来存储值的属性,也就是说它不能用来存储实际的数值,而是相当于函数。只是这个函数被封装成了属性的形式。而且包含有getter和setter两个方法
【7】类属性。类属性不依赖于具体的实例。他是属性类的共有属性。
*/
struct ClassRoom {
static var masxClassRoom = 0;
}
class Student {
var classID = 0;
var claseeName = "";
let masStudent = 100;
lazy var city = cityInfo();
var trueName:String?{
willSet{
print("trueName will be set \(newValue)");
}
didSet{
print("trueName did set\(oldValue)");
}
}
var width = 0;
var round:Int{
get{
return width * 4;
}
set{
print("\(newValue)");
width = newValue/4;
}
}
}
let nana = Student();
nana.classID = 00;
nana.claseeName = "哈哈";
nana.city = cityInfo();
nana.city.cityName = "北京";
nana.city.cityID = 010;
nana.trueName = "真实名称";
nana.width = 4;
nana.round = 10; //set
print("\(nana.round)"); // 10\4 == 2 2 *4 == 8 //get
ClassRoom.masxClassRoom = 1000;
print("\(ClassRoom.masxClassRoom)");