Repository navigation
SwiftUIQuery can now stop periodic refresh after a request exhausts its retry budget, and resume after a successful manual refresh or shared cache update.
Changes
- Add typed
refetchIntervalcallbacks to bothQueryResultandObservableQueryResult. Return a positive duration to poll ornilto disable the timer while keeping observation attached. - Re-evaluate intervals as query state changes, including during a pending timer. Existing fixed intervals keep their behavior.
- Add
retryOnMountandrefetchOnMountBoolean options, both enabled by default, to control the initial load on lifecycle restart independently of manual refresh and polling. - Support state-based policies in weak-owner initializers and configuration updates. Ordinary
update()retains the policy; the explicit overload can replace or clear it. - Preserve lifecycle cancellation and memory ownership guarantees.
Usage
let query = QueryResult<[Product]>(
key: "products",
options: QueryOptions(retry: 2, retryOnMount: false),
refetchInterval: { state in
state.isSuccess ? .seconds(20) : nil
}
) {
try await service.products()
}The same initializer works with ObservableQueryResult on iOS 15. Product and service belong to your app. Each request gets at most three attempts. A terminal error pauses polling; a successful await query.refetch() resumes it.
Validation
- All 98 package tests passed, including 12 new tests for state-based polling, mount policies, configuration, cancellation, and memory lifetime.
- SwiftUI examples and iOS 15 API compatibility checks passed.
- Optimized Swift package Release build and iOS Simulator Release build passed.
- GitHub Actions CI passed for the release commit.
Update your Swift Package dependency to 0.1.2. Requirements remain Swift 6.0+, iOS 15+, and macOS 14+.