Init & Deinit & ARC

Init & Deinit

1、switf中,init不返回值,只负责初始化成员变量。在init方法中可以初始化常量。

  Init & Deinit & ARC

2、默认初始化。

  Init & Deinit & ARC

3、Swift provides an automatic external name for every parameter in an initializer if you don’t provide an external name yourself. 

4、structure types automatically receive a memberwise initializer if they provide default values for all of their stored properties and do not define any of their own custom initializers.

  Init & Deinit & ARC

5、Note that if you define a custom initializer for a value type, you will no longer have access to the default initializer (or the memberwise structure initializer, if it is a structure) for that type.

6、指定的初始化构造函数规则:

  Init & Deinit & ARC

7、定义convenience initializer:

  

8、如果本类没有定义任何designated initializer,compiler会自动为本类生成一个designated initializer,此initializer会继承父类的的designated initilizer。

9、通过Closure设置初始值。

  Init & Deinit & ARC

ARC

1、使用weak变量来解除强引用环:

  Init & Deinit & ARC

2、使用unowned变量来解除强引用:

  Init & Deinit & ARC

3、通过Capture List来破除Closure与self的强引用:

  Init & Deinit & ARC

你可能感兴趣的:(init)