RVS_WeakObjectReference

public struct RVS_WeakObjectReference<T> : Equatable, Hashable where T : AnyObject

This allows us to maintain collections of weak references.

USAGE:

Create instances of RVS_WeakObjectReference, with the values being the objects that you want to aggregate weakly. Aggregate these instances.

Each instance keeps a hash of the original object, even if that object is released, so we can use these as hashable keys or set members.

Note

Remember to access the value property of each instance, instead of the instance, itself. The value will always be an optional, and may be nil.

Inspired by this SO answer

  • Main Initializer

    Declaration

    Swift

    public init(value inValue: T)

    Parameters

    inValue

    The object reference.

  • Initializer (No parameter name).

    Declaration

    Swift

    public init(_ inValue: T)

    Parameters

    inValue

    The object reference.

  • A read-only public accessor of the stored value (may be nil, if the object was deallocated).

    Declaration

    Swift

    public var value: T? { get }
  • A read-only public accessor of the stored hash value. This will always be available.

    Declaration

    Swift

    public var hashValue: Int { get }
  • Hashable Conformance

    Declaration

    Swift

    public func hash(into inoutHasher: inout Hasher)

    Parameters

    inoutHasher

    The hasher to receive the hashed key.