- 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.
- SQL Server 2016 數據庫教程(第4版)
- 云數據中心基礎
- Spark大數據分析實戰
- PySpark大數據分析與應用
- 大話Oracle Grid:云時代的RAC
- Starling Game Development Essentials
- Hands-On Mathematics for Deep Learning
- HikariCP連接池實戰
- Google Cloud Platform for Developers
- 菜鳥學SPSS數據分析
- Expert Python Programming(Third Edition)
- Filecoin原理與實現
- 大數據用戶行為畫像分析實操指南
- 數據分析實踐:專業知識和職場技巧
- INSTANT Windows Powershell 3.0 Windows management Instrumentation Starter