- Swift Functional Programming(Second Edition)
- Dr. Fatih Nayebi
- 167字
- 2021-07-02 23:54:23
Immutability
Swift makes it possible to define variables as mutable and immutable. The let keyword is used for immutable declarations and the var keyword is used for mutable declarations. Any variable that is declared with the let keyword will not be open to change. In the following examples, we define aMutableString with the var keyword so that we will be able to alter it later on; in contrast, we will not be able to alter aConstString that is defined with the let keyword:
var aMutableString = "This is a variable String"
let aConstString = "This is a constant String"
In FP, it is recommended to define properties as constants or immutables with let as much as possible. Immutable variables are easier to track and less error-prone. In some cases, such as CoreData programming, the software development kit (SDK) requires mutable properties; however, in these cases, it is recommended to use mutable variables.
Immutability and stateless programming will be covered in detail in Chapter 9, Importance of Immutability.
- 從零開始學Hadoop大數據分析(視頻教學版)
- Architects of Intelligence
- Creating Dynamic UIs with Android Fragments(Second Edition)
- 數據驅動設計:A/B測試提升用戶體驗
- 大數據營銷:如何讓營銷更具吸引力
- 大數據Hadoop 3.X分布式處理實戰
- 數字媒體交互設計(初級):Web產品交互設計方法與案例
- 數據庫應用系統開發實例
- 一本書講透Elasticsearch:原理、進階與工程實踐
- Deep Learning with R for Beginners
- 大數據分析:R基礎及應用
- 數據庫原理與設計實驗教程(MySQL版)
- 云工作時代:科技進化必將帶來的新工作方式
- AndEngine for Android Game Development Cookbook
- Unity for Architectural Visualization