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

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.

主站蜘蛛池模板: 新巴尔虎右旗| 南昌县| 同仁县| 汉源县| 施甸县| 吴旗县| 墨玉县| 临湘市| 泰和县| 吉林省| 沁源县| 东丰县| 宁化县| 肇州县| 定日县| 双牌县| 太保市| 商城县| 阿瓦提县| 镇平县| 榆林市| 通辽市| 全南县| 清远市| 屏东市| 祁门县| 三原县| 西宁市| 怀仁县| 德阳市| 雅江县| 营山县| 泸水县| 和田县| 巍山| 翼城县| 涟水县| 龙游县| 海阳市| 阳信县| 南漳县|