- Swift Functional Programming(Second Edition)
- Dr. Fatih Nayebi
- 196字
- 2021-07-02 23:54:29
Initialization
The process of preparing an instance of a class, structure, or enumeration for use is called initialization. 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 intermediate state. We can modify the value of a constant property at any point during initialization as long as it is set to a definite value by the time initialization finishes. Swift provides a default initializer for any structure or base class that provides default values for all of its properties and does not provide at least one initializer itself. Consider the following example:
class ShoppingItem {
var name: String?
var quantity = 1
var purchased = false
}
var item = ShoppingItem()
The struct types automatically receive a member-wise initializer if we do not define any of our own custom initializers, even if the struct's stored properties do not have default values.
Swift defines two kinds of initializers for class types:
- Designated initializers: Methods that are able to fully initialize the object
- Convenience initializers: Methods that rely on other methods to complete initialization
- 數據庫基礎與應用:Access 2010
- Word 2010中文版完全自學手冊
- Python數據挖掘:入門、進階與實用案例分析
- Test-Driven Development with Mockito
- Hadoop與大數據挖掘(第2版)
- 數據庫技術及應用教程
- 一個64位操作系統的設計與實現
- 網站數據庫技術
- Hadoop集群與安全
- Oracle 11g+ASP.NET數據庫系統開發案例教程
- 數據庫原理與設計實驗教程(MySQL版)
- Kubernetes快速進階與實戰
- Delphi High Performance
- Managing Software Requirements the Agile Way
- 反饋:化解不確定性的數字認知論