swift语言点评十七-Designated Initializers and Convenience Initializers

Posted zzfx

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了swift语言点评十七-Designated Initializers and Convenience Initializers相关的知识,希望对你有一定的参考价值。

Swift defines two kinds of initializers for class types to help ensure all stored properties receive an initial value. These are known as designated initializers and convenience initializers.

Designated:指定的;特指的

全初始化与部分初始化

Designated Initializers and Convenience Initializers

Designated initializers are the primary initializers for a class. A designated initializer fully initializes all properties introduced by that class and calls an appropriate superclass initializer to continue the initialization process up the superclass chain.

 

Convenience initializers are secondary, supporting initializers for a class. You can define a convenience initializer to call a designated initializer from the same class as the convenience initializer with some of the designated initializer’s parameters set to default values.

以上是关于swift语言点评十七-Designated Initializers and Convenience Initializers的主要内容,如果未能解决你的问题,请参考以下文章

Swift的 convenience && designated init

swift语言点评八-枚举

swift语言点评二

swift语言点评三 - Basic Operators

swift语言点评十二-Subscripts

swift语言点评十九-类型转化与检查