DevQiao Keep on hacking

Swift基础语法(五)

本篇作为Swift的第四篇,主要介绍了Swift中的枚举类型,它和其它语言相比有其特殊性

本篇作为Swift的第四篇,主要简述Swift中的属性、方法

属性(Properties)

Properties are variables and constants that comprise the attributes of a named type.

可存储属性(stored properties)

默认值(Default values)

可计算属性(computed properties)

Getter和Setter

类型属性(Type properties)

单例模式(Singleton pattern)

Using Singleton is a powerful way to share data between different parts of your code without having to pass the data around manually.

属性观察(Property observers)

a way to listen to property changes

限制变量(Limiting a variable)

延迟加载属性(lazy stored property)

The lazy keyword prevents a value of a stored property from being calculated until your code uses it for the first time. You’ll want to use lazy initialization when a property’s initial value is computationally intensive or when you won’t know the initial value of a property until after you’ve initialized the object.

方法(Methods)

comments powered by Disqus