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

Automatic Reference Counting

Reference Counting only applies to instances of classes. Structures and enumerations are value types, not reference types, and are not stored and passed by reference.

Weak references can be used to resolve strong reference cycles and can be defined as follows:

weak var aWeakProperty 

An unowned reference does not keep a strong reference hold on the instance it refers to. Unlike a weak reference, however, an unowned reference is always defined as a non-optional type. A closure capture list can be used to resolve closure strong-reference cycles.

A capture in a closure can be defined as an unowned reference when the closure and the instance that it captures will always refer to each other and be deallocated at the same time.

A capture as a weak reference can be defined when the capture's reference may become nil at some point in the future. Weak references are always of an optional type. Consider the following example:

class AClassWithLazyClosure { 
lazy var aClosure: (Int, String) -> String = {
[unowned self] (index: Int, stringToProcess: String) -> String in
// closure body goes here
return ""
}
}

Classes, objects, and reference types will be covered in detail in Chapter 10, The Best of Both Worlds - Combining FP Paradigms with OOP.

主站蜘蛛池模板: 安泽县| 长兴县| 金昌市| 内江市| 贡嘎县| 亚东县| 南澳县| 高尔夫| 元朗区| 邵阳县| 涡阳县| 浦东新区| 大丰市| 阜城县| 南木林县| 常山县| 蒲江县| 蓝山县| 女性| 武宣县| 保德县| 全南县| 武穴市| 彩票| 安达市| 济源市| 墨玉县| 耒阳市| 通江县| 贵州省| 庆阳市| 太保市| 固安县| 通榆县| 阿巴嘎旗| 土默特右旗| 浮梁县| 太谷县| 巴彦县| 沭阳县| 乌拉特后旗|