fileStorage(_:decoder:encoder:)

Creates a shared key that can read and write to a Codable value in the file system.

FileStorageKey.swift:37
static func fileStorage<Value>(_ url: URL, decoder: JSONDecoder? = nil, encoder: JSONEncoder? = nil) -> Self where Self == FileStorageKey<Value>, Value : Decodable, Value : Encodable, Value : Sendable

Parameters

url

The file URL from which to read and write the value.

decoder

The JSONDecoder to use for decoding the value.

encoder

The JSONEncoder to use for encoding the value.

Returns

A file shared key.

For example:

struct Settings: Codable {
  var hapticsEnabled = true
  // ...
}

@Shared(.fileStorage(.documentsDirectory.appending(component: "settings.json"))
var settings = Settings()