Registry
public class Registry<T>
Registry is a generic class designed to keep track of items (of type T)
in a thread-safe way.
The lifetime of an item in the registry is determined by the Receipt that
was returned when the item was registered.
You must maintain at least one strong reference to the returned Receipt for
the duration of the time that you want the item it represents to remain
registered. Once the Receipt deallocates, the associated item is removed
from the registry.
-
The signature of a function to be called when a registrant is being de-registered.
Declaration
Swift
public typealias DeregistrationHookFunction = (_ registry: Registry<T>, _ registrant: T, _ receipt: Receipt) -> Void -
The number of registered items.
Declaration
Swift
public var count: Int -
An optional
DeregistrationHookFunctionwhich, if set, will be called when an item is being de-registered.Declaration
Swift
public var deregistrationHook: DeregistrationHookFunction? -
Creates a new
Registryusing the specifiedLockMechanism.Declaration
Swift
public init(lock mechanism: LockMechanism = .readWrite)Parameters
mechanismA
LockMechanismvalue that governs the type of lock used for protecting concurrent access to the registry. -
Adds an item to the registry.
You must maintain a reference to the returned
Receiptfor as long as you wish to haveitemregistered. When theReceiptdeallocates,itemwill be deregistered. You can also force deregistration prior to deallocation by calling theReceipt‘sderegister()function.Declaration
Swift
public func register(_ item: T) -> ReceiptParameters
itemThe item to register.
Return Value
A
Receiptthat controls the duration ofitem’s registration with the receiver. -
The items currently in the
Registry.Declaration
Swift
public var registrants: [T] -
Performs the given function once for each registered object.
Declaration
Swift
public func withEachRegistrant(perform function: (T) -> Void)Parameters
functionA function to perform on each object currently registered with the receiver.
View on GitHub
Registry Class Reference