- 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.
- LibGDX Game Development Essentials
- 數據庫技術與應用教程(Access)
- Hands-On Machine Learning with Microsoft Excel 2019
- 云計算環境下的信息資源集成與服務
- Java Data Science Cookbook
- 從0到1:JavaScript 快速上手
- Oracle PL/SQL實例精解(原書第5版)
- 云原生數據中臺:架構、方法論與實踐
- R語言數據挖掘
- IPython Interactive Computing and Visualization Cookbook(Second Edition)
- Construct 2 Game Development by Example
- Instant Autodesk AutoCAD 2014 Customization with .NET
- Solaris操作系統原理實驗教程
- SQL Server 2012實施與管理實戰指南
- Internet of Things with Python