Actors
The following actors are available globally.
-
A storage actor for storing objects in memory.
Memory<T>provides thread-safe in-memory storage using Swift’s actor isolation. It’s used as the underlying storage forMemoryStoragebut can also be used directly when you need fine-grained control over storage operations.Thread Safety
As an actor,
Memory<T>ensures all storage operations are thread-safe by serializing access. Multiple concurrent tasks can safely call storage methods without external synchronization.Persistence
Data stored in
Memory<T>exists only in RAM and is lost when the app terminates. For persistent storage, useKeychain<T>or other storage implementations.Example Usage
let memory = Memory<User>() // Save a user try await memory.save(item: currentUser) // Retrieve the user if let user = try await memory.get() { print("Found user: \(user.name)") } // Delete the user try await memory.delete()See moreSee also
Declaration
Swift
public actor Memory<T> : Storage where T : Decodable, T : Encodable, T : SendableParameters
TThe type of the object to be stored. Must conform to
Codablefor serialization andSendablefor safe concurrent access.
View on GitHub
Actors Reference