Rolling your own SDUI vs a Swift package
A weekend switch statement works until unknown types, nested widgets, and Swift 6. A package is FlowCore plus FlowRender plus your registry.
Rolling your own SDUI vs a Swift package is an engineering-cost question. A weekend switch on a Codable enum works until unknown types, nested widgets, and Swift 6 isolation show up in the same week. A package, in the Flow-UI shape, is FlowCore plus FlowRender plus a registry you own in the app.
This is not a ranking of frameworks. It is the point where gists stop and production starts. SDUI for Swift is the definition. How to build server driven UI in SwiftUI is the four-seam path. Installation and open source are how you take the package if the DIY list below looks like your next two quarters.
What the weekend build usually is#
- An enum of widgets with associated
Codablepayloads. - A
switchin a SwiftUI view that returnsAnyView. URLSessionin the same type that decodes.try JSONDecoder().decode(Page.self, from: data)that fails the whole page on one bad child.
Noah Little's Medium pieces on enum Codable synthesis, and Jacob Bartlett's backend-driven SwiftUI switch, are the industry pattern this refuses. A closed enum cannot learn a type the binary does not name. An unknown hologram_projector either crashes the decode, blanks the page, or disappears without a key path.
Nested widgets make the enum recursive. Accordion, stacks, and "children: [Widget]" force indirect enums, type erasure, and a decode stack you will debug at 1 a.m. Swift 6 then asks whether View initializers are main-actor and whether decode is Sendable. The gist did not.
The list you will rewrite anyway#
- Lossy arrays so one malformed button does not empty a row
- Diagnostics with coding paths
- Stable ids so refresh does not reset steppers
- Layout chrome in one modifier order
- Actions as data, not
NavigationLinkinside every widget - A theme seam for hex, dark hex, and tokens
- Image loading you already own, not a secret third-party library inside the renderer
- UIKit hosting for the app you have, not the rewrite you keep postponing
A package is that list with tests. DIY is that list as tribal knowledge.
What the Swift package actually is#
Flow-UI ships three library products. FlowWidgets is a module of eight starter widgets included in the umbrella, not a fourth product you have to pick in Xcode.
| Product / module | What it holds |
|---|---|
FlowUI | Umbrella: schema, renderer, starter widgets |
FlowCore | Schema and decoding. Foundation only, no SwiftUI |
FlowRender | SwiftUI engine without the starter catalogue |
FlowWidgets | Eight worked examples you can override |
FlowCore is the DIY escape hatch that is still a package: backend tests, fixture validators, CLI tools. It compiles anywhere Swift runs because it does not import SwiftUI.
The registry is open. registry.register(OrderCardWidget.self) is the whole extension story. Last registration for a type string wins, so you override a starter widget without forking. Adding a type never patches framework source.
Networking stays yours. The framework performs no HTTP.
Deeplinks stay yours. There is no router in the package.
When DIY still wins#
A single feed surface with three widget types that will not grow, no nested children, no old binaries, and a team that will not hire into this code. Jacob Bartlett's specialised-versus-generic warning applies: a cart row decoder is fine. Re-implementing HTML in JSON is not. If your DIY is specialised and small, keep it.
A package is overhead if you will not version the contract, will not log diagnostics, and will not register a fifth type. Be honest. When not to use server driven UI is the product-level version of that honesty.
Forking MIT code is also DIY with a head start. The licence allows it. You then own the fork. Prefer registering widgets in the app target first; that is the designed extension point.
A migration path from the enum#
You do not have to delete the gist on Monday. A workable sequence:
- Stop decoding the whole page as one enum. Decode through an open table even if the table only knows your three types.
- Make unknown types skip instead of
throw. Record a path. You have invented a worseDecodeDiagnostics; replace it when you adopt FlowCore. - Move
URLSessionout of the view. That isPageLoaderwhether you write the protocol or copy it. - Put nested children through the same table. Accordion is the test: if children need a second enum, the design is still closed.
- Turn on Swift 6 language mode and move view construction onto the main actor. Flow-UI already did this; you will do it anyway.
At step 1 you can depend on FlowCore only and keep your renderer. At step 3 you are ready for FlowRender. Starter widgets are optional; FlowWidgets.register(on:) is a convenience, not a tax.
Tests you get for free by not DIY-ing decode#
FlowCore tests are fixture based. You can copy that idea even if you never import the package: a JSON file, a decoder, assertions on the surviving widgets and the recorded problems. UI tests still belong on the real page for gestures. Decode tests are how you stop arguing about whether the CMS "should have worked".
Cost that is not lines of code#
Swift 6 language mode is the default on every Flow-UI target. WidgetView is @MainActor. Decode is detached in PageStore. If your weekend view decodes JSON in body, the language mode is not why it feels brittle. Swift 6 and MainActor widgets is the isolation post.
Unknown types on old App Store binaries are a production fact. Containment plus diagnostics is the difference between a missing promo and a crashed home page. Decode diagnostics in production is how you operationalise that.
Nested widgets are one registry, not a second enum. Accordion is the starter example.
MIT, not a seat licence#
The package is MIT licensed. Commercial apps, no paid tier, no key. Source: github.com/ayushmishracognitain/FlowUI. You can still choose DIY. You should not choose DIY because you thought a Swift package implied a vendor lock and a invoice.
Read next#
- Installation is SPM and the product table.
- Open source is MIT, contributing, and what the licence allows.
- SDUI for Swift and how to build server driven UI in SwiftUI are the definition and the tutorial.
Rolling your own SDUI vs a Swift package: the switch statement is a prototype; unknown types, nesting, and Swift 6 are the product. FlowCore plus FlowRender plus your registry is that product as a dependency.
Related documentation
Get started
Installation
Add the Flow-UI server driven UI package to an iOS or macOS app with Swift Package Manager. Requires iOS 17, no third party dependencies.
Resources
Open source
Flow-UI is a free, MIT licensed open source server driven UI framework for SwiftUI. Use it commercially, fork it, or contribute on GitHub.
Related articles
- Architecture6 min read
How a server driven rendering engine works
The rendering engine walks sections, resolves each widget type in the registry, and lays out native SwiftUI. Unknown types drop out.
- Architecture6 min read
Server driven UI architecture
A server driven UI architecture on iOS is decode, registry, contain failures, render widgets, dispatch actions. Flow-UI names those types.
- Architecture4 min read
When not to use server driven UI
Skip SDUI for maps, heavy gestures, latency-critical canvases, and apps that change UI once a quarter. Use it for feeds, merchandising, onboarding, and experiments.
More on the blog.
Read the source
Flow-UI is MIT licensed. The schema, renderer and starter widgets live on GitHub.
GitHubGet started with Flow-UI
Install the Swift package, register a widget, and render a page from JSON.
Get started