Properties & Method

Properties

1、lazy property,通过@property来定义, lazy property的属性直到使用的时候才初始化:

  

2、Computed Properties:

  

  

2、对于set方法,如果没有定义参数,则参数默认为newValue:

 

3、通过去除set方法,以及去除get关键字,即可定义一个readonly属性:

  

4、observers:

  

5、定义Type Property:

  

Method

1、可以通过self来引用内部变量。

      

2、mutating修饰的方法可以修改变量:

  

3、mutating方法中给self赋值:

  

4、定义Type Method:

  

  在Type Method中,self指向type本身。

  

原文地址:https://www.cnblogs.com/tekkaman/p/3790771.html