Swift类属性
来源:互联网 发布:dd打车软件 编辑:程序博客网 时间:2024/06/05 22:49
/**
在进行类的定义时,可以定义三种属性:对象属性,计算属性,类属性
【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)");
- Swift类属性
- Swift 类与属性
- Swift类属性定义
- swift 属性定义 存储属性、计算属性、类属性
- Swift中类的属性
- Swift类的属性监听器
- Swift - 类扩展, 添加属性
- Swift属性
- Swift -- 属性
- swift属性
- Swift 属性
- Swift属性
- Swift 属性
- Swift属性
- 【Swift】属性
- Swift-属性
- swift 属性
- Swift 属性
- java基础之字节流(IO流)
- 如何让echarts在extjs5中自适应大小
- Oracle声明变量
- cocos2dx 3.6 webview背景透明(ios android)
- 关于maven项目的整合
- Swift类属性
- testSuit
- jquery获取一组复选框的值
- Oracle存储过程和包管理
- jQuery Mobile 学习五
- ZZULIOJ 1793: 有趣的球(简单数学)
- sql常用语句整理(包括增删改查)
- 14.3.3 InnoDB Buffer Pool Configuration InnoDB Buffer Pool 配置:
- angularJS学习之路(二十五)---创建服务的五大方法---provider