r/SwiftUI • u/lanserxt • 1h ago
Tutorial iOS 27.1: DeviceHinge
r/SwiftUI • u/AutoModerator • Oct 17 '24
Hello, the mods of r/SwiftUI have agreed to update rule 2 regarding app promotions.
We've noticed an increase of spam accounts and accounts whose only contribution to the sub is the promotion of their app.
To keep the sub useful, interesting, and related to SwiftUI, we've therefor changed the promotion rule:
By only allowing apps that are open source, we can make sure that the app in question is more than just 'inspiration' - as others can learn from the source code. After all, an app may be built with SwiftUI, it doesn't really contribute much to the sub if it is shared without source code.
We understand that folks love to promote their apps - and we encourage you to do so, but this sub isn't the right place for it.
r/SwiftUI • u/lanserxt • 1h ago
r/SwiftUI • u/Street-Lab7620 • 4h ago
For my project omarchy-macos (Omarchy's Linux desktop look, on macOS), I rebuilt Omarchy's QML bar panels as a SwiftUI menu-bar app: Wi-Fi, audio, Bluetooth, power, display, calendar and weather.
Some things that were interesting to solve:
- Porting QML layouts to SwiftUI with the same metrics and font scale
- Following the theme live: every panel re-renders from a palette file when you switch themes
- Talking to CoreAudio, CoreWLAN, IOBluetooth and DisplayServices directly
- A ~30 KB C client so clicks on the bar open panels instantly (launching the Swift binary added visible lag)
It's built with swiftc and a shell script, no Xcode project. Source (MIT):
https://github.com/prashantkoirala465/omarchy-macos/tree/main/src/barpanel
Feedback on the code is welcome.
r/SwiftUI • u/JUMPERSSQUAD • 1h ago
r/SwiftUI • u/Pathfinder-electron • 2h ago
I released the source for two SwiftUI apps I built for iPhone and iPad.
Nodex's app entry is a SwiftUI App. It's an agentless Linux server monitor over SSH, and it shows host health, services, logs, and Docker or Podman containers.
Termex's app entry is also a SwiftUI App, with SwiftUI screens for servers, keys, known hosts, settings, and onboarding. It's an SSH client with tmux session continuity and native SFTP. Some supporting views also use UIKit.
Both are MIT.
Nodex: https://github.com/magrathean-uk/Nodex Termex: https://github.com/magrathean-uk/Termex
r/SwiftUI • u/prio732 • 10h ago
I built a native SwiftUI iPad/iOS/MacOS client app (not a chromium or browser control hosted like most of the people do) for a local LLM served by any OpenAI-compatible server over the LAN. It’s a chat harness with streaming, conversation history, tool calling, and settings. Partially as a learning exercise in building a harness and partially as a way to access my LLM when I am away from my computer. Here’s the repo: https://github.com/alexyak/Sparkle
Planning to add more features like skills, agents… etc.. There’s an option to use a local on-device Apple model as well.
Disclaimer: I have a decades-long experience in software and application development, including iOS development, but I have been gladly accepting the help from Claude Coding agents 😉.
r/SwiftUI • u/Friday4252 • 17h ago
r/SwiftUI • u/beatpaq • 18h ago
TabView(selection: $selection) > Tab > FeedView
Trying to implement a TikTok style feed and I want the FeedView to know when another tab has been opened so I can stop the music/video from playing. I tried onDisappear on the FeedView but it lags behind for a few moments. Should I pass the value of the currently selected tag to the feed view or is there a better way to do this?
r/SwiftUI • u/V0RT3X_L33T_ • 17h ago
Our codebase has hundreds of `@Environment` call sites. Any one of them can crash in production with "No Observable object of type X found" if a view gets shown without the value injected somewhere above it, and the compiler can't see it. Every fix I found started with "first, change all your call sites."
So I built Snagless, a SwiftPM/Xcode build plugin. It reads your SwiftUI source with SwiftSyntax, works out which view shows which across modules, and fails the build when a view can appear without a value it needs. Zero code changes, about 90 ms on a 431-file app.
Built with Claude Code, and the write-up is upfront about every time the AI was wrong and what caught it.
Write-up: https://tarek-builds.dev/p/swiftui-environment-crashes-compile-just-fine-so-i-made-them-fail-the-build/
Repo: https://github.com/tareksabry1337/snagless
Happy to answer questions.
r/SwiftUI • u/Super-Storage6685 • 18h ago
I build for SwiftUI, AppKit and UIKit on Mac, iPhone and iPad, and my layout used to start with a workspace. A project template can create and open a project, but it can't leave you in an open workspace.
r/SwiftUI • u/balshaan_s • 1d ago
r/SwiftUI • u/raviseta07 • 2d ago
I've been exploring SwiftUI performance and wanted to understand something more deeply: why do views sometimes update even when the properties they display haven't changed?
I created a small project called Redraw Lab to reproduce this behavior.
Only tick changes, approximately 60 times per second.
With ObservableObject, all three cards can be invalidated because they observe the same object's objectWillChangepublisher.
Switching to u/Observable allows SwiftUI to track the properties each view reads. Consequently, only the ticker-related views need to update.
I also included:
Self._printChanges() debugging instructions.In my experiment, the number of view bodies executed per tick went from 13 to 4.
One important detail: the workspace and projects cards deliberately perform simulated work to make unnecessary updates easier to observe. The measurements are illustrative of this particular setup.
GitHub: https://github.com/raviseta/SwiftUI-Performance-measurement
I'm interested in feedback from other SwiftUI developers.
Do you generally prefer u/Observable for new projects, or are there situations where you still find ObservableObjectmore appropriate?
I'd appreciate suggestions for extending this experiment.
r/SwiftUI • u/beatpaq • 1d ago
r/SwiftUI • u/giusscos • 1d ago
If you are interested, the full project is here: Github link
A small stack of tabs at the bottom that opens into a full card when you tap or drag it up. Works in light and dark themes and respects Reduce Motion.
Inspired by the tabs in the Focus Travel iOS app.
Source: https://repgem.com/tab-stack-ios
Would love your feedback!
r/SwiftUI • u/Mobile_Two9711 • 3d ago
I hit a navigation bug in a SwiftUI photo review screen. The grid showed pending photos first, while the horizontal filmstrip followed library order. With A, B, C in the library, I marked B as pending, advanced to C, went back to B, and changed it to Keep. Review jumped to A because it used the reordered grid index.
The fix was to use stable item IDs in both views and derive the display order and review order from the same model. The grid can move pending items to the top. The filmstrip and the next-unreviewed action both walk the library sequence. Here’s the simplified lookup.
func nextUnreviewed(
after currentID: String,
libraryIDs: [String],
reviewedIDs: Set<String>
) -> String? {
guard let index = libraryIDs.firstIndex(of: currentID) else { return nil }
return libraryIDs.dropFirst(index + 1).first { !reviewedIDs.contains($0) }
}For the LazyHStack, I use scrollTargetLayout() and scrollPosition(id:anchor:) with a centered ID. Tapping an arrow sets the selected ID and moves the anchor. During a finger drag, anchor changes update the selection during the interacting and decelerating phases.
The regression test starts with B pending. Change B to Keep, check that C is selected, and check that B is still visible between A and C in the filmstrip with its new badge. That test caught the jump even when the individual views looked correct.
r/SwiftUI • u/Ecstatic-Club5254 • 3d ago
Hey r/SwiftUI,
I built ThemeKit, a small, zero-dependency Swift 6 package for managing app themes across iOS 17+, macOS 14+, and watchOS 10+.
GitHub: https://github.com/demolaf/ThemeKit DocC Docs: https://demolaf.github.io/ThemeKit/
Define your theme struct (ThemeKitSwiftUI makes Color directly Codable), pair light and dark presets in a ThemeVariant, add a typed accessor on Theme, and attach .applyTheme at the root:
import ThemeKit
import ThemeKitSwiftUI
struct AppColors: ThemeExtension {
static let fallback = AppColors(tint: Color(hex: 0x007AFF), colorScheme: .light)
var tint: Color
var colorScheme: SystemColorScheme
}
struct AppColorsVariant: ThemeVariant {
let id: String
let light: AppColors
let dark: AppColors
static let `default` = AppColorsVariant(
id: "default",
light: AppColors(tint: Color(hex: 0x007AFF), colorScheme: .light),
dark: AppColors(tint: Color(hex: 0x0A84FF), colorScheme: .dark)
)
static let all: [AppColorsVariant] = [.default]
}
extension Theme {
var colors: AppColors { value(AppColors.self) }
}
struct MyApp: App {
private var theme = Theme()
var body: some Scene {
WindowGroup {
ContentView()
.environment(theme)
.applyTheme(theme, default: .default, available: AppColorsVariant.all)
}
}
}
struct ContentView: View {
@Environment(Theme.self) private var theme
var body: some View {
Text("Hello")
.foregroundStyle(theme.colors.tint)
}
}What it handles out of the box
ThemeExtension works with any Codable & Equatable & Sendable struct, so you can store font names, asset catalog image names, spacing tokens, or anything else your design system needs alongside Color..applyTheme handles first-launch defaults, tracks system light/dark changes when theme.followsSystem is true, and applies window-level appearance overrides on iOS and macOS (and scoped SwiftUI color-scheme styling on watchOS 10+).ThemeOverridable): If you want users to pick a custom accent color without losing the rest of their active preset, declare overridable key paths via props. theme.merge(_:) overlays only those fields, and compare(to:) tells you whether anything drifted from the preset so you can conditionally show a "Reset to Preset" button.UserDefaults by default, or you can conform to ThemeStorage to persist in Keychain, CloudKit, an app group, or an in-memory store for tests.ThemeKitUIKit product (iOS) using `@CodableColor` with the same hex encoding format if you have a hybrid SwiftUI/UIKit app.I'd love any feedback on the API ergonomics, edge cases you've run into with multi-theme SwiftUI apps, or anything you'd want to see added next.
r/SwiftUI • • 4d ago
When tapping a button in a .confirmationDialog (at least one tied to a .bottomBar ToolbarItem), a ridiculously long delay — about a full second after the dialog closes — occurs before the action triggers. This issue is present in some of Apple's apps, including Reminders, Shortcuts, and Notes, but notably not in the Photos app. It also occurs for .alert, though to a lesser degree. How can I eliminate this, preferably without dropping down to UIKit?
The problem has been present since iOS 26. I haven't checked whether it existed before then.
Example code:
struct ContentView: View {
@State private var confirmationDialogPresented = false
@State private var colorToggled = false
var body: some View {
NavigationStack {
Color(colorToggled ? .blue : .red)
.ignoresSafeArea()
.toolbar {
ToolbarItem(placement: .bottomBar) {
Button("Placeholder", systemImage: "square") {
confirmationDialogPresented = true
}
.confirmationDialog("Placeholder", isPresented: $confirmationDialogPresented) {
Button("Placeholder") {
colorToggled.toggle()
}
}
}
}
}
}
}
#Preview {
ContentView()
}
r/SwiftUI
•
u/romit5587
•
4d ago
Most SwiftUI scroll jank I've debugged came from a short list of causes, not from SwiftUI being slow. Here's the order I check them in. Curious what others would add.
Before changing anything, I profile on a real device with a release build, using Instruments (the SwiftUI template plus Time Profiler). `Self._printChanges()` in `body` is also handy for seeing why a view re-rendered. Debug builds and the simulator can point you at the wrong problem.
What's the most surprising cause of scroll jank you've run into?
r/SwiftUI • u/crack_ios_interviews • 3d ago
This is a bug I still see in SwiftUI interviews and in production screens: a view creates its own model with @ObservedObject, and then a form, a score, or a draft “snaps back” to zero after the parent redraws.
struct Screen: View {
@ObservedObject
var vm = Model()
var body: some View {
Text("\(vm.count)")
}
}
If the parent view redraws Screen, does count reset to zero?
Yes. @ObservedObject does not own the object. It is only a way to subscribe to an object someone else already owns. When the parent redraws, this Screen value is created again, Model() runs again, and you get a brand-new view model. The old count is gone.
The fix is to own the object with @StateObject when the view is the one creating it:
struct Screen: View {
@StateObject
var vm = Model()
var body: some View {
Text("\(vm.count)")
}
}
@StateObject keeps the first instance for this view’s identity, so later redraws reuse it.
Use @ObservedObject (or @Bindable / an @Observable value passed in, on newer OS versions) only when a parent already owns the object and passes it down. The rule of thumb I use: if the view writes = Model(), it should be @StateObject. If the view receives the model as an argument, it should be @ObservedObject.
Happy to go deeper on the @Observable / @State equivalent if that’s useful.
I really liked the Trip launch animation, so I recreated it. The logo's letters get swallowed by the orange dot, the dot stretches into a streak, and a circle sweeps in to reveal your first screen.
Source: https://repgem.com/trip-splash-ios
Would love your feedback!
Inspired by the Trip.com app. The code is original and not affiliated with them.
r/SwiftUI • u/Cheap-Engineering21 • 4d ago
r/SwiftUI • u/Lebanoneh • 4d ago
I make Glossbeam, an open-source macOS app that shows an explanation beside selected text. The screenshot shows the UI problem: the answer needs to sit close enough to the selection to make their relationship clear, while leaving room to keep reading. I’d be interested in how other Mac developers handle positioning near a display edge. The Mac and Shared source and Xcode build instructions are here: https://github.com/YasserShkeir/glossbeam-open.