RORK LABJP
MAX — Rork Max generates native Swift for iPhone, iPad, Apple Watch, Apple TV, and Vision Pro, with 2-click App Store publishing and no Xcode requiredSTACK — Standard Rork builds cross-platform mobile apps with React Native (Expo); choosing between the two by use case is the key decisionFOCUS — Unlike web-first tools such as Bolt or Lovable, Rork specializes in native iOS and Android app generationBUGS — A hands-on review reports Rork resolved about 70% of bugs without manual help, with the remaining 30% needing edits in the exported codebaseFUNDING — Rork raised $2.8M from a16z (Andreessen Horowitz)PRICING — It is free to start, with paid plans from $25/month, so you can try before committingMAX — Rork Max generates native Swift for iPhone, iPad, Apple Watch, Apple TV, and Vision Pro, with 2-click App Store publishing and no Xcode requiredSTACK — Standard Rork builds cross-platform mobile apps with React Native (Expo); choosing between the two by use case is the key decisionFOCUS — Unlike web-first tools such as Bolt or Lovable, Rork specializes in native iOS and Android app generationBUGS — A hands-on review reports Rork resolved about 70% of bugs without manual help, with the remaining 30% needing edits in the exported codebaseFUNDING — Rork raised $2.8M from a16z (Andreessen Horowitz)PRICING — It is free to start, with paid plans from $25/month, so you can try before committing
Articles/Dev Tools
Dev Tools/2026-06-17Advanced

Offline-First Sync for SwiftData in Rork Max — Merging Changes Without Conflicts

How to make the SwiftData apps Rork Max generates sync offline-first so edits survive a flaky connection. Instead of overwriting whole rows, we merge per change, propagate deletes with tombstones, and queue writes that can be resent — shown in code, with the production trade-offs that actually mattered.

Rork Max167SwiftData2Offline SyncConflict Resolution2MergeArchitecture11

Premium Article

I was reordering a wallpaper collection on my iPad, walked into a subway station, and when I reopened the app after the gate the order had snapped back to where it started — and it was my own app. The save had succeeded locally, but the moment I came back online the server's stale state overwrote it.

The apps Rork Max generates are native Swift, so local persistence is straightforward with SwiftData. But "saved locally" and "won't be lost after sync" are two different guarantees. Here is how I structure offline-first sync that survives a flaky connection — by treating sync as merging changes, not overwriting rows.

Why "it saved" can't be trusted

Many sync implementations send the device's entire current state to the server and write the server's entire state back. That works while one device touches the data in one direction. It breaks the instant a second device appears: a favorite you set on iPhone and an order you changed on iPad clobber each other through whichever "whole" syncs last.

The root issue is choosing the row — the record's final state — as the unit of sync. Final state only tells you which side is newer. What you actually need is the history of changes: who touched which field, and when. Move the unit from row to change, and edits to different fields can coexist without conflict.

Give the SwiftData model sync metadata

Start by adding the metadata each model needs for sync decisions: an update timestamp, a logical-delete flag (a tombstone), and a local-only flag for whether it is synced.

import SwiftData
import Foundation
 
@Model
final class WallpaperItem {
    @Attribute(.unique) var id: UUID
    var title: String
    var sortIndex: Int
    var isFavorite: Bool
 
    // --- sync metadata ---
    var updatedAt: Date          // when the "content" last changed
    var isDeleted: Bool          // tombstone (never hard-delete)
    var dirty: Bool              // are there unsent local changes?
    var revision: Int            // version number assigned by the server
 
    init(id: UUID = UUID(), title: String, sortIndex: Int) {
        self.id = id
        self.title = title
        self.sortIndex = sortIndex
        self.isFavorite = false
        self.updatedAt = .now
        self.isDeleted = false
        self.dirty = true
        self.revision = 0
    }
}

Three things matter here. Make id a UUID shared with the server so identity holds across devices. Make deletion a logical isDeleted so the fact of deletion can itself be synced. And keep dirty so the device remembers which unsent edits it owes the server once the signal returns.

Thank you for reading this far.

Continue Reading

What follows includes implementation code, benchmarks, and practical content we hope you'll find useful. This site runs without ads — server and development costs are supported entirely by members like you. If it's been helpful, we'd be truly grateful for your support.

WHAT YOU'LL LEARN
A SwiftData model carrying sync metadata, plus a field-level merge that does not blindly let the last write overwrite everything
A delete model that propagates as a tombstone instead of removing the row, so an item can't quietly resurrect on the other device
An outbox queue that never discards edits when the signal drops, with an idempotency key that prevents the same change being saved twice
Secure payment via Stripe · Cancel anytime

Unlock This Article

Get full access to the rest of this article. Buy once, read anytime. This site is ad-free — your support goes directly toward keeping it running.

or
Unlock all articles with Membership →
Share

Thank You for Reading

Rork Lab is ad-free, supported entirely by members like you. We publish practical guides daily with implementation code, benchmarks, and production-ready patterns. If you've found it useful, we'd love to have you on board.

  • Copy-paste ready implementation code
  • New advanced guides published daily
  • $5/mo or $10 for lifetime access
View Membership →

Related Articles

Dev Tools2026-06-16
Designing CloudKit Sync in a Rork Max Native App — Handling Conflicts and Deletes
You want the same data on iPhone and iPad. When you add CloudKit to a Swift app generated by Rork Max, the hard part is not saving — it is conflicts and deletes. Here are the design decisions I settled on.
Dev Tools2026-06-16
Adding SwiftData to a SwiftUI App Generated by Rork Max
Rork Max can produce polished SwiftUI screens, but persistence often stops at @State. Here is how I layer SwiftData onto generated code: model design, wiring the container to views, and a schema migration pattern that survives shipping.
Dev Tools2026-06-15
Drawing the Line Between Rork Max's Swift Output and the Expo Build
Rork Max now generates native Swift, while the standard Rork keeps producing Expo (React Native) apps. Here is how to split responsibilities between the two engines inside a single app business, viewed from real maintenance cost.
📚RECOMMENDED BOOKS
Build a Large Language Model (From Scratch)
Sebastian Raschka
LLM Dev
Prompt Engineering for LLMs
Berryman & Ziegler
Prompting
AI Engineering
Chip Huyen
AI Eng
* Contains affiliate links
See all →