- Swift Functional Programming(Second Edition)
- Dr. Fatih Nayebi
- 211字
- 2021-07-02 23:54:29
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.
- 數(shù)據(jù)庫技術(shù)與應(yīng)用教程(Access)
- Python金融大數(shù)據(jù)分析(第2版)
- Architects of Intelligence
- Python廣告數(shù)據(jù)挖掘與分析實(shí)戰(zhàn)
- 分布式數(shù)據(jù)庫系統(tǒng):大數(shù)據(jù)時(shí)代新型數(shù)據(jù)庫技術(shù)(第3版)
- Live Longer with AI
- Ceph源碼分析
- 中國數(shù)字流域
- 一個(gè)64位操作系統(tǒng)的設(shè)計(jì)與實(shí)現(xiàn)
- 數(shù)據(jù)庫技術(shù)實(shí)用教程
- Chef Essentials
- 跨領(lǐng)域信息交換方法與技術(shù)(第二版)
- 大數(shù)據(jù)分析:數(shù)據(jù)倉庫項(xiàng)目實(shí)戰(zhàn)
- 大數(shù)據(jù)技術(shù)原理與應(yīng)用:概念、存儲(chǔ)、處理、分析與應(yīng)用
- openGauss數(shù)據(jù)庫核心技術(shù)