swift语言点评十六-Initialization && Deinitialization

initial value:必须初始化、不影响观察者

Classes and structures must set all of their stored properties to an appropriate initial value by the time an instance of that class or structure is created. Stored properties cannot be left in an indeterminate state.

You can set an initial value for a stored property within an initializer, or by assigning a default property value as part of the property’s definition. These actions are described in the following sections.

When you assign a default value to a stored property, or set its initial value within an initializer, the value of that property is set directly, without calling any property observers.

 

Default Property Values:另一种初始化方式;

 

Parameter Names and Argument Labels

As with function and method parameters, initialization parameters can have both a parameter name for use within the initializer’s body and an argument label for use when calling the initializer.

 

Optional Property Types

 Properties of optional type are automatically initialized with a value of nil,

 

Assigning Constant Properties During Initialization

常量可以在初始化时赋值;

 

Default Initializers

条件:1、所有参数都有缺省参量;2、没有初始化函数;

 

Memberwise Initializers for Structure Types

结构体可以有以属性为参量的缺省构造器,类没有;

 

Initializer Delegation for Value Types:初始化代理

区分于引用类型:值类型、引用类型。

?没有明白?

self.init只能在初始器内部使用。

For value types, you use self.init to refer to other initializers from the same value type when writing your own custom initializers. You can call self.init only from within an initializer.

 

Class Inheritance and Initialization

 

转载于:https://www.cnblogs.com/feng9exe/p/8717341.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值