-
Notifications
You must be signed in to change notification settings - Fork 0
Observing Changes
Husnain Ali edited this page Sep 27, 2026
·
1 revision
React to writes with a typed change feed or a live query.
changes(of:) yields a StorageChange for every write to a type made through
this storage instance:
for await change in storage.changes(of: User.self) {
switch change {
case .inserted(let user), .updated(let user): show(user)
case .deleted(let user): hide(user)
case .cleared, .expired: reload()
}
}updates(of:options:) yields the current results immediately, then again after
each burst of writes, coalesced into a single refetch:
.task {
do {
for try await users in storage.updates(of: User.self, options: FetchOptions(sort: .newestFirst)) {
self.users = users
}
} catch {
self.error = error
}
}For indexed types, updates(of:matching:orderedBy:options:) is the same live query
with an in-store filter (see Indexed Fields).
Both streams end when the consuming task is cancelled.
SwiftLocalStorage, licensed under Apache 2.0. These pages cover v1.1.1.