Gravity
SwiftUI library for data fetching
Lightweight
Any Backend
Fast
Designed for SwiftUI
SwiftPM Ready
Realtime Support
Gravity is a SwiftUI library for remote data fetching. I acts as a Network Layer for your SwiftUI app, providing a simple and declarative way to fetch data from the server. It uses stale-while-revalidate
technonology to fetch data from the server, a cache invalidation strategy popularized by HTTP RFC 5861 (opens in a new tab).
Gravity first returns the data from cache (stale), then sends the fetch request (revalidate), and finally comes with the up-to-date data again.
With Gravity, components will get a stream of data updates constantly and automatically. And the UI will be always fast and reactive.
Overview
import SwiftUI
import Gravity
struct LandmarkList: View {
@RemoteObjects<LandmarkBase>(request: .all) var landmarks
var body: some View {
List(landmarks, id: \.id) { landmark in
LandmarkRow(landmark: landmark)
}
}
}
In this example, the property wrapper @RemoteObjects
accepts a request
and returns an array of all the Landmark
.
LandmarkBase
acts as a controller for the Landmark
model. It is responsible for fetching the data from the server and returning it to Gravity. The rest is handled by Gravity.