Latest release: May 1, 2022 • version 0.3.0 • CHANGELOG
Requirements: iOS 13.0+ / macOS 10.15+ / tvOS 13.0+ / watchOS 6.0+ • Swift 5.5+ / Xcode 13+
This package provides the @Query
property wrapper, that lets your SwiftUI views automatically update their content when the database changes.
import GRDBQuery
import SwiftUI
/// A view that displays an always up-to-date list of players in the database.
struct PlayerList: View {
@Query(PlayersRequest())
var players: [Player]
var body: some View {
List(players) { player in
Text(player.name)
}
}
}
@Query
is for GRDB what @FetchRequest
is for Core Data. Although @Query
does not depend on GRDB, it was designed with GRDB in mind.
@Query
solves a tricky SwiftUI challenge. It makes sure SwiftUI views are immediately rendered with the database content you expect.
For example, when you display a List
that animates its changes, you do not want to see an animation for the initial state of the list, or to prevent this undesired animation with extra code.
You also want your SwiftUI previews to display the expected values without having to run them.
Techniques based on onAppear(perform:)
, onReceive(_:perform)
and similar methods suffer from this "double-rendering" problem and its side effects. By contrast, @Query
has you fully covered.
Learn how to use @Query
in the Documentation, or jump straight to the Getting Started guide.
Check out the demo app, and the GRDB demo apps for various examples of @Query
uses.
🙌 @Query
was vastly inspired from Core Data and SwiftUI by @davedelong, with a critical improvement contributed by @steipete. Many thanks to both of you!
link |
Stars: 56 |
Last commit: 2 minutes ago |
Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics