WeakArray
public class WeakArray<T>
A Collection similar to an array, but wraps its Elements in a WeakRef
.
-
Initialize an empty WeakArray
Declaration
Swift
public init()
-
Add an object reference to the array
Declaration
Swift
public func add(object: T)
Parameters
object
the object to weak reference before adding it to the array
-
Dereference the object at index when not released
Declaration
Swift
public func object(at index: Int) -> T?
Parameters
index
index to get
Return Value
The object when not deinitialized
-
Insert an object reference at a specified index
Declaration
Swift
public func insert(object: T, at index: Int)
Parameters
object
the object to weak reference before adding it to the array
index
the index to insert at
-
Replace a weak reference with a new object
Declaration
Swift
public func replaceObject(at index: Int, with object: T)
Parameters
index
the index to replace
object
the object to weak reference before replacing the reference at index
-
Remove an object reference at a specified index
Declaration
Swift
public func removeObject(at index: Int)
Parameters
index
index of the reference to remove
-
Get the current count of available (not-released) object references
Note
complexity O(n) - since we filter out the zeroedWeakRef
sDeclaration
Swift
public var count: Int { get }
Return Value
the current active reference count
-
Dereference the object at index when not released
See
object(at:)Declaration
Swift
public subscript(index: Int) -> T? { get }
Parameters
index
index to get
Return Value
The object when not deinitialized
-
Find the index of an object in the array
Note
complexity O(2n)Declaration
Swift
public func index(of object: T) -> Int?
Parameters
object
the object to search for
Return Value
the index when found else nil
-
Convenience initializer for weak referencing an entire array
Declaration
Swift
public convenience init(objects: [T])
Parameters
objects
the object to weak reference in the newly initialized WeakArray
-
Get objects referenced by
Self
as a strong arrayDeclaration
Swift
public var array: [T] { get }
Return Value
Array with available objects