WeakReference
public final class WeakReference<T> : NSObject
Allows weakly reference another object.
final class MyClass {
// MARK: - Private Properties
private let weakReference: WeakReference<MyOtherClass>
// MARK: Public Functions
func foo() {
guard let reference = self.weakReference.value else {
return
}
// do something with reference which is non-nil
}
// MARK: Initializers
init(myOtherClass: MyOtherClass) {
self.weakReference = WeakReference(myOtherClass)
}
}
-
Returns the weakly referenced value.
Declaration
Swift
public var value: T? { get }