Structure
Storage
A container providing arbitrary storage for extensions of an existing type, designed to obviate the problem of being unable to add stored properties to a type in an extension. Each stored item is keyed by a type conforming to
StorageKey protocol.struct Storage
Topics
Initializers
init(logger:)Create a newStoragecontainer using the given logger.
Instance Methods
asyncShutdown()For every key in the container having a shutdown closure, invoke the closure. Designed to be invoked during an explicit app shutdown process or in a reference type’sdeinit.clear()Delete all values from the container. Does not invoke shutdown closures.contains(_:)Test whether the given key exists in the container.get(_:)Get the value of the given key if it exists and is of the proper type.set(_:to:onShutdown:)Set or remove a value for a given key, optionally providing a shutdown closure for the value.setWithAsyncShutdown(_:to:onShutdown:)Set or remove a value for a given key, optionally providing an async shutdown closure for the value.shutdown()For every key in the container having a shutdown closure, invoke the closure. Designed to be invoked during an explicit app shutdown process or in a reference type’sdeinit.
Subscripts
subscript(_:)Read/write access to values via keyed subscript.subscript(_:default:)Read access to a value via keyed subscript, adding the provided default value to the storage if the key does not already exist. Similar toSwift/Dictionary/subscript(key:default:). ThedefaultValueautoclosure is evaluated only when the key does not already exist in the container.
Relationships
Conforms To
Swift.SendableSwift.SendableMetatype