Skip to content

Commit 4939493

Browse files
Hoang Phamclaude
andcommitted
Update README with Quick Start guide and version 0.2.0
- Add comprehensive Quick Start section with usage examples - Include basic query and infinite query examples - Update installation instructions to version 0.2.0 - Improve feature descriptions and requirements - Add code examples for common use cases 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent fafb2ce commit 4939493

1 file changed

Lines changed: 116 additions & 12 deletions

File tree

README.md

Lines changed: 116 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
11
# SwiftUI Query
22

3-
A Swift implementation of TanStack Query for SwiftUI applications, providing powerful asynchronous state management with caching, synchronization, and more.
3+
A Swift implementation of TanStack Query for SwiftUI applications, providing powerful asynchronous state management with caching, synchronization, and infinite queries.
44

55
## Features
66

7-
- 🚀 Swift 6 compatible with strict concurrency
8-
- 📦 Zero external dependencies
9-
- 🔄 Automatic refetching (on mount, focus, reconnect)
10-
- ⚡️ Request deduplication
11-
- 🗑️ Garbage collection
12-
- 📊 Parallel and dependent queries
13-
- 🔧 Built with Swift Observation framework
14-
- 📱 Support for iOS, macOS, tvOS, and watchOS
7+
- 🚀 **Swift 6 Compatible** - Full strict concurrency support
8+
- 🔄 **Automatic Refetching** - On mount, focus, reconnect
9+
- 📱 **iOS 16+ Support** - Built with Perception library for broad compatibility
10+
- ⚡️ **Request Deduplication** - Automatic request optimization
11+
- 🗑️ **Garbage Collection** - Smart memory management
12+
- 📊 **Infinite Queries** - Built-in pagination support
13+
- 🔧 **Type Safe** - Full Swift type safety
14+
- 📱 **Multi-Platform** - iOS, macOS, tvOS, and watchOS
1515

1616
## Requirements
1717

1818
- Swift 6.0+
19-
- iOS 17.0+ / macOS 14.0+ / tvOS 17.0+ / watchOS 10.0+
19+
- iOS 16.0+ / macOS 13.0+ / tvOS 16.0+ / watchOS 9.0+
2020

2121
## Installation
2222

@@ -26,15 +26,119 @@ Add SwiftUI Query to your `Package.swift` file:
2626

2727
```swift
2828
dependencies: [
29-
.package(url: "https://github.com/muzix/swiftui-query.git", from: "1.0.0")
29+
.package(url: "https://github.com/muzix/swiftui-query.git", from: "0.2.0")
3030
]
3131
```
3232

3333
Or add it through Xcode:
3434
1. File → Add Package Dependencies
35-
2. Enter the repository URL
35+
2. Enter the repository URL: `https://github.com/muzix/swiftui-query.git`
3636
3. Select the version
3737

38+
## Quick Start
39+
40+
### 1. Set up QueryClient
41+
42+
```swift
43+
import SwiftUI
44+
import SwiftUIQuery
45+
46+
@main
47+
struct MyApp: App {
48+
var body: some Scene {
49+
WindowGroup {
50+
ContentView()
51+
.queryClient() // Add QueryClient to environment
52+
}
53+
}
54+
}
55+
```
56+
57+
### 2. Basic Query
58+
59+
```swift
60+
import SwiftUI
61+
import SwiftUIQuery
62+
63+
struct ContentView: View {
64+
var body: some View {
65+
UseQuery(
66+
queryKey: "todos",
67+
queryFn: { _ in
68+
try await fetchTodos()
69+
}
70+
) { result in
71+
switch result.status {
72+
case .loading:
73+
ProgressView("Loading...")
74+
case .error:
75+
Text("Error: \(result.error?.localizedDescription ?? "Unknown error")")
76+
case .success:
77+
List(result.data ?? []) { todo in
78+
Text(todo.title)
79+
}
80+
}
81+
}
82+
}
83+
84+
func fetchTodos() async throws -> [Todo] {
85+
// Your API call here
86+
}
87+
}
88+
```
89+
90+
### 3. Infinite Query
91+
92+
```swift
93+
struct PokemonListView: View {
94+
var body: some View {
95+
UseInfiniteQuery(
96+
queryKey: "pokemon-list",
97+
queryFn: { _, pageParam in
98+
let offset = pageParam ?? 0
99+
return try await PokemonAPI.fetchPokemonPage(offset: offset)
100+
},
101+
getNextPageParam: { pages in
102+
let currentTotal = pages.reduce(0) { total, page in
103+
total + page.results.count
104+
}
105+
return pages.last?.next != nil ? currentTotal : nil
106+
},
107+
initialPageParam: 0
108+
) { result in
109+
ScrollView {
110+
LazyVStack {
111+
// Render all pages
112+
ForEach(result.data?.pages ?? []) { page in
113+
ForEach(page.results) { pokemon in
114+
PokemonRow(pokemon: pokemon)
115+
}
116+
}
117+
118+
// Load more button
119+
if result.hasNextPage {
120+
Button("Load More") {
121+
Task {
122+
await result.fetchNextPage()
123+
}
124+
}
125+
.onAppear {
126+
// Auto-load on scroll
127+
Task {
128+
await result.fetchNextPage()
129+
}
130+
}
131+
}
132+
}
133+
}
134+
.refreshable {
135+
try? await result.refetch()
136+
}
137+
}
138+
}
139+
}
140+
```
141+
38142
## Development
39143

40144
### Setup

0 commit comments

Comments
 (0)