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

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.

主站蜘蛛池模板: 宿迁市| 亳州市| 邮箱| 宣威市| 绥滨县| 浦北县| 无极县| 广安市| 钦州市| 甘德县| 昌黎县| 诏安县| 南充市| 宜川县| 曲沃县| 枣庄市| 韶山市| 河源市| 大英县| 长岛县| 铁岭市| 邢台市| 青川县| 银川市| 邛崃市| 吴堡县| 巢湖市| 丰镇市| 定日县| 蓬安县| 盐山县| 剑河县| 玉门市| 修水县| 包头市| 民权县| 和田县| 河间市| 富平县| 苏尼特右旗| 错那县|