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

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.

主站蜘蛛池模板: 华池县| 黄冈市| 栾城县| 盈江县| 黄骅市| 甘南县| 铁岭市| 大兴区| 扶绥县| 林西县| 柳州市| 三江| 洪江市| 东乌| 玉树县| 芦山县| 哈巴河县| 贺兰县| 博野县| 老河口市| 浮山县| 宿州市| 汨罗市| 海晏县| 宁晋县| 卢氏县| 平塘县| 洛扎县| 水富县| 收藏| 陆川县| 黄梅县| 宁安市| 高雄市| 隆林| 高台县| 班玛县| 西林县| 穆棱市| 阳泉市| 广汉市|