官术网_书友最值得收藏!

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.

主站蜘蛛池模板: 西平县| 徐汇区| 德昌县| 远安县| 威远县| 延川县| 和龙市| 哈密市| 普宁市| 金昌市| 福海县| 贡山| 福海县| 板桥市| 田林县| 邹平县| 大埔区| 南华县| 全南县| 乐安县| 古交市| 科技| 蒙阴县| 镇赉县| 隆德县| 文山县| 新乡县| 绥德县| 信阳市| 遵化市| 渝北区| 潼关县| 高安市| 福贡县| 麻城市| 黔东| 舞阳县| 乌苏市| 东至县| 万宁市| 门头沟区|