appStorage(_:)

Creates a persistence key for sharing data in user defaults given a key path.

AppStorageKeyPathKey.swift:18

This declaration is deprecated: Use 'appStorage' with a supported data type, instead

static func appStorage<Value>(_ keyPath: _SendableReferenceWritableKeyPath<UserDefaults, Value>) -> Self where Self == AppStorageKeyPathKey<Value>, Value : Sendable

Parameters

keyPath

A string key identifying a value to share in memory.

Returns

A persistence key.

For example, one could initialize a key with the date and time at which the application was most recently launched, and access this date from anywhere using the @Shared property wrapper:

@Shared(.appStorage(\.appLaunchedAt)) var appLaunchedAt = Date()