- 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.
- Enterprise Integration with WSO2 ESB
- UDK iOS Game Development Beginner's Guide
- 大數據營銷:如何讓營銷更具吸引力
- 數據庫程序員面試筆試真題庫
- 數據庫原理與應用
- Hadoop大數據開發案例教程與項目實戰(在線實驗+在線自測)
- Visual Studio 2013 and .NET 4.5 Expert Cookbook
- Oracle高性能SQL引擎剖析:SQL優化與調優機制詳解
- 中文版Access 2007實例與操作
- 數據指標體系:構建方法與應用實踐
- MySQL數據庫實用教程
- Oracle 內核技術揭密
- 代碼的未來
- Configuration Management with Chef-Solo
- Learning Construct 2