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

Value types

First, we need to distinguish value types from reference types. Value types aren't reference counted, as they are values. Think of a simple integer; the value in an integer isn't shared across all of its assignments, but copied whenever it's assigned to a new variable:

struct Box {
var intValue: Int
}

let box = Box(intValue: 0)
var otherBox = box
otherBox.intValue = 10
assert(box.intValue == 0) // box and otherBox don't share the same reference
assert(otherBox.intValue == 10)

When you're passing a struct around, the value is behaving like it's copied. This is the same behavior seen when capturing values inside blocks.

主站蜘蛛池模板: 滨海县| 二连浩特市| 武乡县| 白山市| 山丹县| 汨罗市| 阳原县| 射洪县| 屏山县| 家居| 卫辉市| 岳西县| 安康市| 天津市| 田东县| 霍林郭勒市| 安龙县| 香港 | 永顺县| 根河市| 小金县| 休宁县| 巩义市| 广东省| 墨竹工卡县| 合肥市| 长寿区| 伽师县| 若羌县| 潼南县| 周口市| 休宁县| 宜君县| 连城县| 安西县| 龙川县| 老河口市| 成武县| 扬州市| 嘉峪关市| 华宁县|