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

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.

主站蜘蛛池模板: 洛南县| 马鞍山市| 桐梓县| 沁水县| 和田市| 炎陵县| 南平市| 锦州市| 呼图壁县| 韶关市| 保德县| 荥经县| 东海县| 景东| 鱼台县| 迁西县| 泰来县| 小金县| 北川| 柳州市| 迁安市| 龙游县| 昌黎县| 曲阳县| 高邮市| 龙泉市| 泰顺县| 永福县| 南城县| 五莲县| 盘锦市| 尼玛县| 璧山县| 临武县| 武城县| 三门县| 香格里拉县| 兴安盟| 揭西县| 宜川县| 横山县|