r/SwiftUI

SwiftUIBackportKit – A lightweight library for supporting multiple iOS versions in SwiftUI
▲ 21 r/SwiftUI+3 crossposts

SwiftUIBackportKit – A lightweight library for supporting multiple iOS versions in SwiftUI

Hi everyone!

One pain point I've run into repeatedly with SwiftUI is supporting newer APIs while keeping an older deployment target.

Things like `if #available` work well in normal Swift code, but they don't fit naturally in the middle of a modifier chain. That often leads to duplicated views or compatibility helpers scattered throughout a project.

After solving the same problem across multiple apps, I decided to package the patterns into a small open-source library called **SwiftUIBackportKit**.

It includes:

• `.modify { }` for conditional view transforms
• `.backport` for reusable version-gated SwiftUI APIs
• `platformValue(...)` for version-specific values
• `OS.isAtLeast(_:)` for simple runtime version checks

The goal is to keep SwiftUI views focused on describing the UI while isolating deployment-target compatibility in one place.

GitHub:
https://github.com/EmadBeyrami/SwiftUIBackportKit

I'd really appreciate any feedback on the API design, naming, or features you'd like to see. And if you find it useful, a ⭐ on GitHub would mean a lot!

Thanks!

github.com
u/NoCardiologist4405 — 1 day ago
▲ 12 r/SwiftUI

I built an open-source macOS hosts switcher in SwiftUI (with two AppKit escape hatches)

I’ve been building Hostflip, a free and open-source native macOS app for switching /etc/hosts profiles from the menu bar. I thought its SwiftUI/AppKit seams might be useful to share here.

Most of the UI is SwiftUI. MenuBarExtra, the main window, and Settings share a single workspace store built with Swift’s Observation framework. The main window combines a sidebar and editor with a drift review: if another tool edits /etc/hosts, Hostflip stops writing and shows the difference for review instead of silently overwriting it.

Two small AppKit escape hatches were needed:

• NSViewRepresentable with NSTitlebarAccessoryViewController keeps the master switch pinned to the trailing edge. Putting it inside the SwiftUI-managed toolbar made it move whenever SwiftUI rebuilt the toolbar items.

• NSApplicationDelegateAdaptor handles the window lifecycle, so a normal launch opens the main window while a login-item launch remains menu-bar-only.

The privileged boundary stays outside the UI. A minimal root helper exposes a two-method XPC interface: a handshake and a single write operation that atomically replaces the merged hosts content. The app and helper verify each other’s code-signing identity before accepting the connection.

Hostflip is MIT-licensed and notarized. It currently requires macOS 14 or later on Apple silicon.

Source: https://github.com/heronapp/hostflip

I’d especially appreciate feedback on the SwiftUI/AppKit seam and the shared state flow between MenuBarExtra and the main window.

u/East_Call1027 — 1 day ago
▲ 6 r/SwiftUI+1 crossposts

We built a free macOS app that shows you every network request your iOS app makes no proxy, no certificates

Every time I set up a new machine or wiped a simulator, I lost 20 minutes to

proxy certs and trust settings just to see a JSON response. So I built Owlse.

It's a Mac app. You add a Swift Package to your iOS/macOS project, and every

request your app makes streams to your Mac live over Bonjour. No proxy, no

certificate installation, no traffic leaving your machine.

**What's in it**

- Live streaming per device — history survives disconnects, and you can pause

or resume a stream without losing what's already captured

- Full request inspector: Overview, Headers (incl. cookies), Body, Timing, cURL

- Timing breakdown per phase — DNS, TCP, TLS, wait, download — plus protocol

and TLS cipher

- Timeline waterfall, so you can spot serialised chains when a screen feels

slow but no single request looks bad

- WebSocket frames grouped by connection, JSON pretty-printed

- Side-by-side compare that highlights which headers differ between two requests

- Mocks — write a rule (or build one from a captured request) and push it to

every connected device

- Crash reporting — on by default, symbolicated, sent on next launch

- Full-text search across headers *and* response bodies

- HAR export, so you can hand a capture to your backend team

**Setup**

Add the package, drop two keys in your Info.plist, done:

https://github.com/debuging-life/owlse

Free, macOS 13+, Universal and Apple Silicon builds.

Download: https://www.loudowls.com/products/owlse

u/loudowls_corp — 2 days ago

Make Menu() show toggle state in toolbar

Hi! I’m wondering if and how its possible to make a toolbar menu show the state of a toggle inside. I know using Toggle() in the toolbar shows this type of effect but i need a title and description to the toggle for it to make sense. Therefore there needs to be some window to open, which works fine with Menu(). However, that doesn’t show the state of the toggle when closed.

Apple managers to that with the photos app when selecting filters. See example images.

Thanks!

u/Nilsolivier — 2 days ago

Can’t figure out the pattern

I’ve recently made a (what I think is a cool) app that accumulates all the screen time in a fully interactive circle that can also explode to a rainbow. Everything works fine even when I background the app or even if I lock/unlock the phone with the app in the foreground.
Every now and then the UI completely breaks and my circle/rainbow is completely messed up.
Bear in mind I’m using an extension for the data collection using the notoriously scuffed screentimeapi.
I’ve tried everything you could ever think of but sometimes it will still break somehow
The app is very stable atm and I’m willing to give a lifetime support if anyone can help with this.
Is there any patterns you can think of that might be causing UIs to break?

reddit.com
u/ExampleLegitimate348 — 2 days ago

How do you get UIKit's instant keyboard focus (becomeFirstResponder in viewDidLoad) in pure SwiftUI?

In UIKit, if we place titleTextView.becomeFirstResponder() inside viewDidLoad, the keyboard slides up seamlessly alongside the view controller's presentation animation. It looks instant and feels like a native, high-quality UX.

I'm struggling to replicate this exact behavior in SwiftUI.

Whenever I use FocusState and toggle it to true inside .onAppear, there is always a noticeable delay. The view pushes/presents, settles, and then the keyboard decides to slide up.

Has anyone found a way to achieve this instantly in pure SwiftUI yet (maybe in iOS 17+), or is UIViewRepresentable still the only bulletproof way to get that perfectly synced keyboard presentation?

Thanks in advance!

reddit.com
u/yccheok — 2 days ago
▲ 43 r/SwiftUI

Does anyone know how to recreate this menu above the keyboard?

I would like to reproduce this menu above the keyboard in the notes application on swift? Is it natively possible?

u/SeaAdorable7381 — 4 days ago
▲ 6 r/SwiftUI+1 crossposts

How long did Advanced swift (objc.io) actually took you to finish?

I’m a few chapters into Advanced swift by objc.io right now. The concepts are super dense which is great and I’m learning a lot! Really some concepts are just WOW!!!

Usually I’ve noticed for me that concepts to sit clearly in my brain and understanding takes a little longer than I expected so I’m just curious to know how long it took you folks to finish the book? Did you read end to end and also understood the code ? Or cherry picked the topics and studied them need to need basis?

Thank you in advance :)

reddit.com
u/StockStart825 — 3 days ago

TIL: .environment(\.locale) does not select a strings table — how my in-app language picker silently never worked (and fixing it cut my build time by 75%)

Sharing a failure mode that survived in my codebase for months, because the app looked localized the whole time.

Setup: my app has an in-app language picker (independent of the iOS system language), implemented via a language manager that resolves strings from the selected .lproj bundle. Standard approach.

The bug: the overwhelming majority of my UI strings were Text("some.key") — i.e., SwiftUI LocalizedStringKey literals. Those resolve against Bundle.main using the system locale machinery. Setting .environment(\.locale) changes formatting behavior, but it does not select which strings table your keys resolve from. Result: 225 of 269 routed call sites silently bypassed the language override entirely. The picker "worked" for the ~44 call sites that went through the manager, which is exactly why nobody noticed — the app changed some strings on switch and looked plausible in both languages.

Confirmed on-device with diagnostic logging: the resolved bundle for LocalizedStringKey paths was Bundle.main, regardless of the override.

The fix: a tiny helper — L.t(_: String.LocalizationValue) -> String — that resolves through the override bundle (String(localized:bundle:)), and mechanically routing every UI string through it. An enforcement script in lint now flags any bare string in Text/Button/Label/.accessibilityLabel.

The completely unexpected side effect: build times collapsed. Bare LocalizedStringKey literals create expensive type-checker constraint problems (Text("...") has to disambiguate between StringProtocol and LocalizedStringKey overloads at every call site). Replacing them with a concrete String return eliminated that: one heavy view body went from type-checking as my slowest file to ~98% faster, and the whole target build time dropped ~75%. I did not see that coming from a localization refactor.

Two smaller traps from the same audit:

  • String(format:) with catalog plural variations silently returns the raw %#@token@ if you forget to pass locale:.
  • Xcode's string extractor can't see keys behind a helper function, so the catalog stops auto-populating — new keys become a manual (and CI-checked) step. Worth knowing before you commit to the pattern.

Curious if others route in-app language switching differently — is there a cleaner first-party way to point LocalizedStringKey resolution at a non-main bundle that I missed?

reddit.com
u/KREANIQS — 3 days ago
▲ 28 r/SwiftUI+2 crossposts

Trying to use more motion design in my app

As a former motion designer I was a bit disappointed by the lack of motion design in the app market. Since I released my own audio app, I am trying to bring subtile motion design into typography, colours and transitions. I am currently working on a new startscreen, hope you like it! I'd love to see more motion in apps, let me know what you think?

u/oasisaudiolab — 5 days ago

How can I place a search bar at the bottom of the page?

I'd like to reproduce this type of searchable element but at the bottom of the page. I tried using `placement: .bottomBar` but it doesn't work. Does anyone have any ideas?

u/SeaAdorable7381 — 5 days ago

Best AI tool for designing swiftui app interfaces?

None of these output production SwiftUI directly, the real question is which gives the cleanest reference to rebuild from with the least manual cleanup. Tested these for iOS over the last few months.

iSwift.dev is the closest to SwiftUI-native, free screen generator for individual screens, Pro starts at $20/mo for unlimited projects and 1,000 AI prompts per billing period. Generates buildable SwiftUI projects from plain English with views, state and navigation, multi-platform for iPhone, iPad, macOS and Watch. Better for individual screens than full cohesive multi-screen flows, and generated code needs cleanup before production, but it's the only tool actually outputting Swift.

SwiftUI Inspector is a free Figma plugin, Pro is a one-time $49. Exports colors, gradients, text labels, shapes, frames and Auto Layout as SwiftUI code. Handles rotation, opacity, shadows, blend modes, wraps in HStack/VStack/ZStack. Only useful if you already have a Figma design to convert, doesn't generate anything on its own. According to a 2026 comparison of 7 Figma-to-SwiftUI tools, expect to spend 20-50% of design time refining the output from any of them.

Compot is free on the App Store with IAP, 100+ prebuilt SwiftUI components, generates Swift from images or text. Good for grabbing components fast, not built for designing complete multi-screen flows.

Google Stitch is free, 400 daily credits, Gemini 2.5 Pro on experimental mode, exports Figma with layers plus HTML/CSS. Material Design native so everything skews Android, fighting it into HIG patterns takes more effort than it saves for iOS work. No production SLA, single user.

Sleek.design around $20/mo generates complete mobile app screens from a description, runs the same prompt through different models to compare outputs, exports Figma and code. Not iOS-native so HIG spacing and nav need explicit prompting, hits limits on complex custom components, better for early screens than final specs. Pairs well with SwiftUI Inspector on the Figma export to skip some manual rebuild.

Realistic workflow is generate screens fast in sleek or stitch, export to Figma, run SwiftUI Inspector for the base SwiftUI code, clean up by hand. Anyone found a shorter path than this?

u/rash3rr — 6 days ago
▲ 11 r/SwiftUI+2 crossposts

Tien Len - 13: a full SwiftUI card game that outgrew GameKit and ended up on a custom Vapor backend

Hey everyone, I'm the developer. I shipped Tien Len - 13 this week, an iOS version of Tiến Lên (Thirteen), the Vietnamese card game I learned in high school 20 something years ago. Every version on the App Store was ads, coin systems, and casino graphics. Just really ugly stuff. About 4 years ago I started on this, but I finally finished it.

Tech Stack

  • Client: full SwiftUI
  • Server: Vapor 4 (Vapor 5 migration coming), WebSockets for realtime play and SSE for updates
  • Auth: passkeys only, no passwords, no email required
  • No API keys in the binary. The client authenticates to the backend through App Attest, and a jwt from the passkey
  • Feature flags via Grantiva, which is how ranked mode sits built but its currently off while the player base grows

Development Challenge

I originally built multiplayer on GameKit. Free infrastructure, first-party, seemed like the obvious call. It fought me everywhere

  • The authenticateHandler flow hands you view controllers to present, which is clumsy to wire into a pure SwiftUI app cleanly
  • Turn-based matchmaking gave me hard-to-debug timeouts and sync conflicts once real devices on real networks got involved
  • Testing multiplayer meant provisioning sandbox accounts across App Store Connect and Xcode before anything worked, which made iteration painfully slow
  • The core problem: keeping four devices agreed on one table state. GameKit's model is clients exchanging state with each other, so there's no authority anywhere enforcing the rules, and I ended up chasing conflicting snapshots instead of building the game

That last one is what killed it. A card game needs exactly one truth about whose turn it is and what's legal to play. So I replaced GameKit with a custom Vapor backend where the server owns the game. Clients send moves, the server validates them against the rule set and broadcasts new state over WebSockets.

AI Disclosure

Largely self built. Ive been an iOS Engineer for over 13 years, and a Mac engineer before that. The architecture, gameplay, UI, and backend are hand-written. I used AI as a tool in three places: localization, security testing, and verifying game logic edge cases against the rule sets.

The game itself

Offline vs three AI opponents with different play styles, Pass & Play with hand-off screens so nobody peeks at your hand, and online multiplayer with private lobbies, invite codes, and quick match. Southern and Northern rules plus custom house rules for chops, instant wins, and turn timers. Free, with a one-time $4.99 unlock for ranked when it goes live. No ads anywhere.

Up next: an interactive learn mode, emotes, more themes, and something fun you can flick around the table while you wait for your turn.

Happy to go deep on any of it, especially the App Attest setup, the GameKit lessons, or running Swift on the server.

https://apps.apple.com/us/app/tien-len-13/id6758355876

u/unpluggedcord — 6 days ago
▲ 3 r/SwiftUI+3 crossposts

Redesigning my app’s colour system from scratch.

After getting a lot of feedback that Pocket Vault’s was looking a bit boring and bland, I completely redesigned the colour system, added proper light and dark themes, and reworked the overall visual hierarchy in SwiftUi. Here’s the code: https://github.com/AaravB09/Pocket-Vault

Let me know what you think of this new palette! I would love to hear what you guys think. Any feedback is welcome 😄

And if you guys can subscribe to my YouTube channel, I would really appreciate it. Here’s the link : https://youtube.com/@aaravbansal-9?si=-qJ6CmDqqLNPARDz

u/EquivalentCoconut588 — 6 days ago
▲ 117 r/SwiftUI+1 crossposts

[Project] Using Ollama to investigate captured HTTP/WebSocket traffic locally. Feedback on this context and redaction flow?

Hi r/ollama,

I’m Stephen, the indie developer behind Rockxy, an open-source native macOS HTTP debugging proxy.

I’ve integrated Ollama into Rockxy’s AI Assistant so developers can investigate captured HTTP, HTTPS, GraphQL, and WebSocket traffic using a model running on their own machine.

The AI Assistant demonstrates the current flow:

  1. Select one or more captured requests.

  2. Ask a debugging question, such as why a request failed or what changed between two flows.

  3. Rockxy builds a bounded context from only the selected traffic.

  4. Common sensitive values, including authorization headers, cookies, and tokens, are redacted.

  5. Review Data shows the exact context before it is submitted.

  6. After approval, the selected Ollama model processes that context through the configured local Ollama runtime.

  7. The answer streams back with evidence connected to the source requests and suggested follow-up steps.

The Assistant is intentionally read-only. It may prepare a replay, comparison, filter, or another investigation step, but it does not execute those actions automatically.

The main design question is how much network evidence a local model actually needs.

Sending an entire capture session creates noise, wastes context, and may expose unrelated data. Sending only a summary is safer and faster, but could remove the exact header, timing, payload, or WebSocket event that explains the problem.

I would particularly value the community’s opinion on these questions:

- Should the model receive structured request summaries, raw HTTP sections, or a combination of both?

- Is Review Data useful control, or would you prefer a persistent per-project policy after the first approval?

- Which Ollama models and context sizes work well for JSON, REST, GraphQL, and WebSocket debugging on Apple Silicon?

- For multi-request investigations, should Rockxy pre-filter and rank evidence before inference?

- Should suggested actions remain user-confirmed, or would you want an optional agent mode with stricter permissions?

I’m especially interested in results from smaller local models. The goal is not to require the largest model just to explain a failed API request.

Rockxy is native Swift, local-first, and open source under AGPL-3.0:

https://github.com/RockxyApp/Rockxy

Rockxy website:

https://rockxy.io

Please be direct about anything that feels unsafe, slow, confusing, or unnecessary. Architecture suggestions, model recommendations, test cases, issues, and contributions are all welcome.

For r/ollama members who test this with a real debugging session and provide detailed feedback, please DM me your Mac configuration, Ollama model, findings, and the email you plan to use at checkout. I’ll personally send you a private Rockxy Pro tester discount code as a thank-you. The offer is for genuine testing and is not tied to upvotes or stars.

u/locnguyen305 — 8 days ago
▲ 3 r/SwiftUI+1 crossposts

Xcode is doing my nut in. Why does it do this and how do I stop it?

When im in a tab and click to open a new file, instead of opening that file in that tab, it will jump to another tab where the file was open recently and open the file in that tab instead. How do i stop this? Honestly so frustrating.

reddit.com
u/sunrise274 — 6 days ago
▲ 1 r/SwiftUI+1 crossposts

[Dev] I built GitaSandesh - A 100% free app to explore the Bhagavad Gita daily (No ads, no subscriptions)

I created GitaSandesh to make the wisdom of the Bhagavad Gita accessible, clean, and distraction-free in daily life. Whether you're looking for daily quotes, structured reading, or quick verse translations, the goal was to build a simple, beautiful experience for iOS.

Key Features:

  • 📖 Complete Bhagavad Gita – Read chapters and verses with clear translations.
  • 🌅 Daily Inspiration / Sandesh – Get meaningful daily quotes to start your day.
  • 🔍 Search & Bookmark – Easily save your favorite verses for quick reference.
  • 🚫 100% Free – No ads, no paywalls, no subscriptions, and no data tracking.

App Store Link: https://apps.apple.com/us/app/gitasandesh/id6772055132

I’d love to get feedback from this community! If you have suggestions for features, UI tweaks, or localized translations, please let me know in the comments.

Thanks for checking it out! 🙏

u/best_manish — 7 days ago