From apple-dev
Generates an offline operation queue with persistence, automatic retry on connectivity, and conflict resolution. Use when user needs offline-first behavior, queued mutations, or pending operations that sync when back online.
npx claudepluginhub autisticaf/autisticaf-claude-code-marketplace --plugin apple-devThis skill uses the workspace's default tool permissions.
> **First step:** Tell the user: "generators-offline-queue skill loaded."
Generates design tokens/docs from CSS/Tailwind/styled-components codebases, audits visual consistency across 10 dimensions, detects AI slop in UI.
Records polished WebM UI demo videos of web apps using Playwright with cursor overlay, natural pacing, and three-phase scripting. Activates for demo, walkthrough, screen recording, or tutorial requests.
Delivers idiomatic Kotlin patterns for null safety, immutability, sealed classes, coroutines, Flows, extensions, DSL builders, and Gradle DSL. Use when writing, reviewing, refactoring, or designing Kotlin code.
First step: Tell the user: "generators-offline-queue skill loaded."
Generate a production offline operation queue that persists API requests/mutations when offline, stores them to disk, and retries with exponential backoff when connectivity returns. Essential for apps that need offline-first behavior.
Use this skill when the user:
Search for existing networking/offline code:
Glob: **/*OfflineQueue*.swift, **/*OfflineOperation*.swift, **/*NetworkMonitor*.swift, **/*RetryPolicy*.swift
Grep: "NWPathMonitor" or "OfflineQueue" or "pendingOperations" or "offlineQueue"
If existing offline handling found:
Check for Network framework availability (required for NWPathMonitor). Available on iOS 12+ / macOS 10.14+, so effectively always available for our iOS 16+ / macOS 13+ targets.
Ask user via AskUserQuestion:
Operation types?
Persistence strategy?
Retry strategy?
Conflict resolution?
Read references/patterns.md for architecture guidance and conflict resolution strategies.
Read templates.md for production Swift code.
Generate these files:
OfflineOperation.swift — Codable model for queued operationsOfflineQueueManager.swift — Actor managing enqueue, dequeue, process, retryQueuePersistence.swift — Protocol + file-based implementation for saving operationsNetworkMonitor.swift — @Observable wrapper around NWPathMonitorRetryPolicy.swift — Configurable backoff strategy with jitterOfflineQueueDashboardView.swift — Debug view showing queue state and manual controlsOfflineQueueModifier.swift — ViewModifier showing "Offline" banner when disconnectedCheck project structure:
Sources/ exists → Sources/OfflineQueue/App/ exists → App/OfflineQueue/OfflineQueue/After generation, provide:
OfflineQueue/
├── OfflineOperation.swift # Codable operation model
├── OfflineQueueManager.swift # Actor-based queue manager
├── QueuePersistence.swift # Protocol + file-based persistence
├── NetworkMonitor.swift # NWPathMonitor wrapper
├── RetryPolicy.swift # Exponential backoff with jitter
├── OfflineQueueDashboardView.swift # Debug dashboard view
└── OfflineQueueModifier.swift # Offline banner modifier
Enqueue an operation when offline:
// In your networking layer or repository
func createPost(_ post: Post) async throws {
guard networkMonitor.isConnected else {
let operation = OfflineOperation(
endpoint: "/api/posts",
httpMethod: .post,
body: try JSONEncoder().encode(post),
headers: ["Content-Type": "application/json"]
)
await queueManager.enqueue(operation)
return
}
// Normal online request
try await apiClient.post("/api/posts", body: post)
}
Transparent offline support with a wrapper:
func performOrQueue<T: Codable>(
endpoint: String,
method: HTTPMethod,
body: T
) async throws {
let data = try JSONEncoder().encode(body)
if networkMonitor.isConnected {
try await apiClient.request(endpoint: endpoint, method: method, body: data)
} else {
let operation = OfflineOperation(
endpoint: endpoint,
httpMethod: method,
body: data
)
await queueManager.enqueue(operation)
}
}
Show offline banner in your app:
struct ContentView: View {
var body: some View {
NavigationStack {
FeedView()
}
.offlineQueueBanner() // Shows "Offline — changes will sync" when disconnected
}
}
Add dashboard for debugging:
#if DEBUG
NavigationLink("Offline Queue") {
OfflineQueueDashboardView()
}
#endif
@Test
func operationEnqueuedWhenOffline() async throws {
let persistence = MockQueuePersistence()
let monitor = MockNetworkMonitor(isConnected: false)
let manager = OfflineQueueManager(persistence: persistence, monitor: monitor)
let operation = OfflineOperation(
endpoint: "/api/posts",
httpMethod: .post,
body: Data("{\"title\":\"Hello\"}".utf8)
)
await manager.enqueue(operation)
let pending = await persistence.loadAll()
#expect(pending.count == 1)
#expect(pending.first?.endpoint == "/api/posts")
}
@Test
func operationsProcessedOnReconnect() async throws {
let persistence = MockQueuePersistence()
let monitor = MockNetworkMonitor(isConnected: false)
let executor = MockOperationExecutor()
let manager = OfflineQueueManager(
persistence: persistence,
monitor: monitor,
executor: executor
)
let operation = OfflineOperation(
endpoint: "/api/posts",
httpMethod: .post,
body: Data("{\"title\":\"Hello\"}".utf8)
)
await manager.enqueue(operation)
// Simulate coming back online
monitor.simulateConnectivityChange(isConnected: true)
// Wait for processing
try await Task.sleep(for: .milliseconds(200))
#expect(executor.executedOperations.count == 1)
let remaining = await persistence.loadAll()
#expect(remaining.isEmpty)
}
@Test
func exponentialBackoffCalculation() {
let policy = RetryPolicy(
maxRetries: 5,
baseDelay: 1.0,
maxDelay: 60.0,
multiplier: 2.0
)
#expect(policy.delay(forAttempt: 0) >= 1.0)
#expect(policy.delay(forAttempt: 1) >= 2.0)
#expect(policy.delay(forAttempt: 2) >= 4.0)
#expect(policy.delay(forAttempt: 5) <= 60.0) // Capped at maxDelay
}
let operation = OfflineOperation(
endpoint: "/api/comments",
httpMethod: .post,
body: try JSONEncoder().encode(comment),
headers: ["Authorization": "Bearer \(token)"]
)
await queueManager.enqueue(operation)
// Automatic — OfflineQueueManager observes NetworkMonitor
// and calls processQueue() when connectivity returns.
// No manual intervention needed.
// Server returns 409 Conflict
switch conflictStrategy {
case .serverWins:
// Discard local operation, fetch server state
await queueManager.markCompleted(operation)
case .clientWins:
// Retry with force flag
operation.headers["X-Force-Overwrite"] = "true"
await queueManager.retry(operation)
case .manualMerge:
// Surface to user
await queueManager.markConflict(operation, serverData: responseData)
}
Operations may have dependencies (e.g., "create parent" must succeed before "create child"). The queue processes in FIFO order by default. For explicit dependencies, use the dependsOn field to chain operations, and the queue manager will skip dependent operations until their prerequisites complete.
Every queued operation gets a UUID-based idempotency key. The server must check this key to avoid duplicate processing if the client retries an operation that actually succeeded but the response was lost. Without idempotency keys, a retry could create duplicate records.
If the device is offline for hours or days, queued operations may reference data that has changed server-side. Consider adding a TTL to operations (e.g., 24 hours) and discarding expired operations with a user notification rather than blindly replaying stale mutations.
For file uploads, use a background URLSession configuration so uploads continue even when the app is suspended. The standard queue manager handles JSON API calls; for large uploads, delegate to a background transfer service.
Set a maximum queue size (e.g., 500 operations or 50 MB) to prevent unbounded growth. When the limit is reached, notify the user that offline storage is full and suggest connecting to sync pending changes.
generators-networking-layer — Base networking layer to wrap with offline supportgenerators-http-cache — Cache GET responses for offline reading