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


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

Classes and structuresmustset 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 ofnil,

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 useself.initto refer to other initializers from the same value type when writing your own custom initializers. You can callself.initonly from within an initializer.

Class Inheritance and Initialization

优质内容筛选与推荐>>
1、指针运算不同于算数运算,不能简单加减
2、使用自定义的tstring.h
3、认识Flow(一)
4、HTML(2013.12.8)
5、bzoj1067 [SCOI2007]降雨量


长按二维码向我转账

受苹果公司新规定影响,微信 iOS 版的赞赏功能被关闭,可通过二维码转账支持公众号。

    阅读
    好看
    已推荐到看一看
    你的朋友可以在“发现”-“看一看”看到你认为好看的文章。
    已取消,“好看”想法已同步删除
    已推荐到看一看 和朋友分享想法
    最多200字,当前共 发送

    已发送

    朋友将在看一看看到

    确定
    分享你的想法...
    取消

    分享想法到看一看

    确定
    最多200字,当前共

    发送中

    网络异常,请稍后重试

    微信扫一扫
    关注该公众号