- 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.
- 程序員修煉之道:從小工到專家
- Python數據分析與挖掘實戰
- SQL Server 2012數據庫技術與應用(微課版)
- 虛擬化與云計算
- Access 2016數據庫技術及應用
- 大數據算法
- 數據庫應用基礎教程(Visual FoxPro 9.0)
- Spark核心技術與高級應用
- WS-BPEL 2.0 Beginner's Guide
- 大數據架構商業之路:從業務需求到技術方案
- 信息學競賽寶典:數據結構基礎
- Unity 2018 By Example(Second Edition)
- 大數據與機器學習:實踐方法與行業案例
- Spring Boot 2.0 Cookbook(Second Edition)
- 利用Python進行數據分析(原書第2版)