Skip to content

Instance 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 to Swift/Dictionary/subscript(key:default:). The defaultValue autoclosure is evaluated only when the key does not already exist in the container.
subscript<Key>(key: Key.Type, default defaultValue: @autoclosure () -> Key.Value) -> Key.Value where Key : StorageKey { mutating get }