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
objectthe 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
indexindex 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
objectthe object to weak reference before adding it to the array
indexthe index to insert at
-
Replace a weak reference with a new object
Declaration
Swift
public func replaceObject(at index: Int, with object: T)Parameters
indexthe index to replace
objectthe 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
indexindex of the reference to remove
-
Get the current count of available (not-released) object references
Note
complexity O(n) - since we filter out the zeroedWeakRefsDeclaration
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
indexindex 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
objectthe 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
objectsthe object to weak reference in the newly initialized WeakArray
-
Get objects referenced by
Selfas a strong arrayDeclaration
Swift
public var array: [T] { get }Return Value
Array with available objects