- Mastering Swift
- Jon Hoffman
- 130字
- 2021-07-16 14:12:14
Mutability
For those who are familiar with Objective-C, you know that there are different classes for mutable and nonmutable collections. For example, to define a mutable array, we use the NSMutableArray
class, and to define a nonmutable array, we use the NSArray
class. Swift is a little different because it does not contain separate classes for mutable and nonmutable collections. Instead, we define whether a collection is constant (nonmutable) or a variable (mutable) by using the let
and var
keywords. This should seem familiar since, in Swift, we define constants with the let
keyword and variables with the var
keyword.
Note
It is good practice to create immutable collections unless there is a specific need to change the objects within the collection. This allows the compiler to optimize the performance.
- C#高級編程(第10版) C# 6 & .NET Core 1.0 (.NET開發(fā)經(jīng)典名著)
- C語言程序設計習題解析與上機指導(第4版)
- ReSharper Essentials
- ASP.NET Core Essentials
- Django Design Patterns and Best Practices
- Animate CC二維動畫設計與制作(微課版)
- Mastering Swift 2
- INSTANT OpenNMS Starter
- TypeScript項目開發(fā)實戰(zhàn)
- 網(wǎng)站構(gòu)建技術
- Teaching with Google Classroom
- AIRIOT物聯(lián)網(wǎng)平臺開發(fā)框架應用與實戰(zhàn)
- MongoDB,Express,Angular,and Node.js Fundamentals
- Go語言精進之路:從新手到高手的編程思想、方法和技巧(2)
- 大話Java:程序設計從入門到精通