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

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.

主站蜘蛛池模板: 博兴县| 桐乡市| 南昌市| 安新县| 东平县| 光泽县| 新兴县| 安龙县| 剑阁县| 揭阳市| 和平县| 贡觉县| 双桥区| 万安县| 柳河县| 河池市| 永丰县| 沁源县| 山阳县| 高唐县| 伽师县| 衡山县| 建平县| 白朗县| 修武县| 交口县| 弥勒县| 大邑县| 洞头县| 蒙阴县| 弥渡县| 大城县| 定远县| 塘沽区| 全州县| 永泰县| 鹤岗市| 固镇县| 志丹县| 高唐县| 咸丰县|