r/SwiftUI • • 1h ago

Promotion (must include link to source code) a TimelineView in a MenuBarExtra label never stops redrawing, and other things i learned building a menu bar app in swiftui (open source)

Enable HLS to view with audio, or disable this notification

• Upvotes

source first: https://github.com/lucasnsaraujo/ebb (mit)

i built ebb, a mac menu bar app that shows how much is left of a pool of claude code and codex accounts behind cliproxyapi. the whole ui is swiftui with a bit of appkit where swiftui runs out, and a few things bit me along the way

TimelineView inside a MenuBarExtra label is a trap. the label redraws the moment you ask it to, so a periodic timeline there just keeps spinning. in the label i use a .task(id:) loop that sleeps 60s and bumps a now state instead, and it stops when the item is hidden. inside the panel TimelineView is fine, i use it for the freshness line and the "locked until" note

the menu bar item is one NSImage, not a swiftui label. that way the mark, a 3pt gap and the text land exactly where i want. plain states are template images so the menu bar tints them like its own items. the low/empty states are tinted so they can't be templates, there the drawing handler resolves colors against the appearance it's drawing in, and it redraws when increase contrast changes

MenuBarExtra has no api to open its panel. for the shortcuts/siri action that opens it i ended up finding the status item's button and pressing it, and keeping a flag so a second press doesn't close the panel

numbers use .contentTransition(.numericText(value:)) so the percentages roll, and fall back to .identity with reduce motion on

i built it with claude code, happy to answer anything about the swiftui side


r/SwiftUI • • 2h ago

Tutorial iOS 27: Now Playing Framework

Thumbnail
antongubarenko.substack.com
2 Upvotes

r/SwiftUI • • 6h ago

Promotion (must include link to source code) my first mac app: a menu bar log of what grew on your disk, built with swiftui

2 Upvotes

my first real mac app, built with swiftui and a lot of ai help (not gonna lie, im a webdev not a swift dev lol)

i got way to little storage in my mac and kept running out of space without a clear why. disk tools show a big chart of whats on disk, not what changed. so i wanted something that just tells me what grew and when (caches, docker images, downloads, installs, whatever)

prunr sits in the menu bar and keeps a simple list of what grew on your disk, by day and by app. click a row to see the folders, open them in finder. nothing leaves your mac.

its open source (MIT) if anyone wants to poke around or open prs

https://github.com/merlinkraemer/prunr

a dmg is also avaliable here:
https://merlinkraemer.github.io/prunr/

still in early testing so any help is appreciated! lmk what you think :)


r/SwiftUI • • 7h ago

Tutorial Swift 6.4: Async defer doesn't make cleanup cancellation-safe

Thumbnail
sagarsaurav.medium.com
8 Upvotes

I wrote a technical walkthrough of a subtle Swift Concurrency issue I wanted to explore.

Imagine a task writing data into a buffered writer. The task gets cancelled, defer runs, and close() gets called. But if close()invokes a cancellation-aware flush(), that flush can throw CancellationError. If the error is swallowed and the writer is marked closed anyway, the cleanup path has run without achieving its intended postcondition.

The article explores two Swift Evolution proposals:

  • SE-0493: Async calls in defer bodies
  • SE-0504: Task Cancellation Shields

It covers a minimal reproduction, the limits of using Task.detached for cleanup, a narrowly scoped cancellation shield, and a Swift Testing example that checks whether the data was actually flushed rather than merely checking whether close() was called.

One important caveat: the example demonstrates a cancellation-aware cleanup failure, not a claim that every real file API corrupts data when cancelled.

I'd be interested in feedback on the cancellation-shield approach, especially around resource ownership and cleanup guarantees in production code.


r/SwiftUI • • 15h ago

Promotion (must include link to source code) I built a native macOS browser in Swift + SwiftUI (WebKit). Here’s what I learned

Thumbnail scadavide55.github.io
0 Upvotes

For the past few months I’ve been building Lumen, a native macOS browser written in Swift and SwiftUI on top of WKWebView. I wanted to learn Swift properly, and a browser touches everything: UI, performance, storage and security. It’s taught me more than any tutorial.

All the releases are from today because I’d already built the whole browser but never put it on GitHub, so I just uploaded all the versions I’d made. (If you see gaps between the uploads, it’s because I was running the tests, building the DMGs and so on.)

Some things I ran into:

  • SwiftUI redraws: every tab row was observing the whole browser state, so loading progress on one tab redrew the entire sidebar. Fixed it with .equatable() rows that take plain values, and by moving fast-changing state (load progress, pull-to-refresh) into separate small ObservableObjects.
  • Profiles with WKWebsiteDataStore(forIdentifier:): removing a store while the app is running fails with “in use”, and calling it before WebKit has initialised crashed the app. So I erase the data immediately and remove the folder at the next launch.
  • Resumable downloads: resumeDownload(fromResumeData:) works well, but decide(destination:) is not called again on resume, so you have to keep track of the destination yourself.
  • History moved from JSON to SQLite: I was rewriting a 10k-entry JSON file on every visit. Now it’s SQLite in WAL mode with writes on a background serial queue, so one visit is one INSERT OR REPLACE.
  • Battery and memory: idle background tabs hibernate in Low Power Mode (NSProcessInfoPowerStateDidChange) and on memory pressure (DispatchSource.makeMemoryPressureSource).
  • Self-updating without Sparkle: it downloads from GitHub Releases and checks the file with a SHA256 (CryptoKit) and codesign --verify --deep --strict before replacing itself.

Tech: Swift, SwiftUI, WKWebView, SQLite. No Electron, no third-party dependencies.
It’s completely free and open source.
Download it from: scadavide55.github.io/Lumen
Code: github.com/scadavide55/Lumen

It’s still a work in progress (latest pre-release is 1.5.2), so code review and criticism are very welcome. What would you have done differently?


r/SwiftUI • • 23h ago

I built a zero-cloud macOS & iPad productivity HUD with Swift and SwiftUI (open-source)

0 Upvotes

Hey everyone! I wanted a purely native, zero-cloud heads-up display that turns an iPad next to my Mac into an active control surface.

I ended up building Cockpit (MIT licensed, Swift 5.10 + SwiftUI): - Peer-to-peer encryption via Network.framework (zero cloud telemetry) - Contextual hotkeys adapting to active apps (Xcode, Safari, Notion) - 120Hz ProMotion SwiftUI quadrant architecture

Homebrew: brew install --cask Yvsleyen00941/tap/cockpit Live showcase: https://yorben.me/#cockpit GitHub: https://github.com/Yvsleyen00941/Cockpit


r/SwiftUI • • 1d ago

Question How do you verify VoiceOver focus and spoken order after a state change, not just what it announces?

0 Upvotes

I can check VoiceOver labels and traits on a static screen fairly easily. The part I still find harder to verify is what happens immediately after a state change.

For example, after a toggle is switched, a list is filtered or reordered, or the language and reading direction change, I want to know three things: where does focus land, in what order are the items then spoken, and does an announcement happen at all — or does VoiceOver simply go quiet while the screen has changed underneath it?

What I am trying to separate is the announcement from the journey. A correct announcement does not necessarily mean focus landed somewhere sensible, and a sensible landing spot does not necessarily mean the new order makes sense when it is spoken from there.

So I am curious how other SwiftUI developers actually check this in practice:

  • Do you test mainly on a real device, and if so, what do you do differently there compared with the simulator or Accessibility Inspector?
  • After a change, do you deliberately move focus, or do you check where VoiceOver takes you without touching anything first?
  • How do you check spoken order when items have been reordered or filtered — by stepping through the whole list again, or by checking the changed region only?
  • What do you record for each case? I have been noting the starting element, the action, the element focus lands on, the spoken sequence, and whether any announcement fired at all, but I am not sure that is the right set.

One clear question, then: what is your repeatable method for verifying focus landing and spoken order after a state change, and what does it catch that a simple label check misses?


r/SwiftUI • • 1d ago

Question Changing row color in List

2 Upvotes

Hi everyone.

Is there a way in SwiftUI to change list row color without killing all interaction highlights stuff?

Example:

List row has some default background color for iOS view. On tap, it highlights. On iPad or in sidebar in general, it has no background until the item is selected, then it has capsule shaped background. When interacting with row using swipe actions, it adds another highlight + rounded corners to the row.

What I tried:

- Simple .listRowBackground kills all interaction highlights and transparency for sidebar Lists.

- I tried replacing NavigationLink with Button and creating my own custom button style. This allowed me to bring highlight-on-tap back, but it introduced more problems. I failed to properly control swipe gesture highlight and rounded corners, sidebar transparency and such. Every time I tried custom solutions, something else broke or did not work as intended. I also realized with this approach, that List component does not have same default row insets for all screen sizes. iPhone Max has bigger insets than small iPhone, iPad even bigger. They are also orientation dependant.

Is there a way to change row background color without loosing all of default system interaction stuff? GitHub app for example has custom color and still has interaction highlights and so on. Do they use UIKit for this and would I need to rework my Lists in UIKit to get same possibility?


r/SwiftUI • • 2d ago

Your iPhone Can Run an LLM Locally — A Hands-On Swift Guide to Foundation Models in iOS 27

Thumbnail
medium.com
0 Upvotes

r/SwiftUI • • 2d ago

built a text dissolve animation for my app

Enable HLS to view with audio, or disable this notification

154 Upvotes

wanted clearing a note to feel a little more satisfying so i built this text dissolve effect using swiftui and uikit

the editor uses UITextViewso instead than deleting text character by character, i take a snapshot of the editor and use textkit to find the position of each line

let layout = textView.layoutManager
layout.ensureLayout(for: textView.textContainer)

let glyphs = layout.glyphRange(
    for: textView.textContainer
)

layout.enumerateLineFragments(forGlyphRange: glyphs) {
    _, usedRect, _, _, _ in
    lineRects.append(usedRect)
}

i crop the snapshot into individual lines and animate each one using core animation. each line fades out with a slight blur and scale effect

it seams like a pretty simple trick, hope i didnt over complicate it haha


r/SwiftUI • • 3d ago

Promotion (must include link to source code) Using SwiftUI timer text as a frame mask in watchOS complications (source + caveats)

3 Upvotes

I've been adapting the timer/font technique to Apple Watch complications in TV Watch. The idea isn't mine: Bryce Bostwick demonstrated it for iPhone widgets in WidgetAnimation and this walkthrough. My first attempt converted video frames into font glyphs on the iPhone. That approach failed when I tried to load those custom fonts, transferred from iPhone, on the Apple Watch. I then adapted Bryce’s approach: bundle a fixed masking font with the Watch extension and keep the video frames as images, so importing a new clip does not require loading a newly generated font.

The useful distinction is that WidgetKit can update a system-rendered timer without running your extension every second. That does not give you an ordinary SwiftUI animation loop. Instead:

  1. Prepare opaque image frames ahead of time.
  2. Draw each frame behind timer text in a custom font. The font's shaping rules turn selected timer values into a filled rectangle and the others into an empty mask.
  3. Offset each layer's timer so it reveals its frame at the intended point in the loop.

In the 2 fps version, a gate stays open for a second but layers start half a second apart. Two frames can therefore be visible at once: stacking newer opaque frames above older ones is what makes the sequence work. It isn't just one timeline entry per frame.

The core composition looks like this (excerpt, not a standalone example):

swift Image(decorative: frames[index], scale: 1) .resizable() .scaledToFit() .mask { Text(anchor.addingTimeInterval(offset), style: .timer) .font(.custom(gateFontName, fixedSize: fontSize)) .foregroundStyle(.white) .lineLimit(1) .environment(\.locale, Locale(identifier: "en_US_POSIX")) .environment(\.layoutDirection, .leftToRight) }

The tricky part is the end of the loop: high-index layers otherwise cover the beginning of the next pass. I put the last-second frames in a separately gated group and keep an unmasked frame zero underneath to avoid a blank gap if timer updates arrive late.

Public code: renderer and font generator, under MIT. Disclosure: it's my repository. The whole app still has a private dependency for its legacy renderer, so a fresh clone isn't a self-contained build; the linked renderer and generator are public to inspect.

Limits worth keeping explicit: watchOS controls redraw timing, so 2 fps is a target rather than a guarantee. I use a static frame for Always-On/Reduce Motion in the weather complication. I don't have a controlled battery comparison, and this isn't a promise that future OS releases will preserve the behavior.

Has anyone else worked with staggered system timers on watchOS, particularly late updates around the loop boundary?


r/SwiftUI • • 3d ago

Promotion (must include link to source code) [Open Source] Thought Meadow: SwiftUI notes with Arabic/English RTL and native Markdown/checklist preview

4 Upvotes

I'm sharing the MIT-licensed SwiftUI source for Thought Meadow, my small iPhone notes app. The full Xcode project, assets and build instructions are browsable here:

Source and build instructions

A few implementation details that may be useful to other SwiftUI developers:

  • Language and direction: the root sets both locale and layoutDirection for English/Arabic, and changing the language recreates the root view using its language ID. WaraqaApp.swift
  • Editor and preview: writing uses TextEditor bindings into the note store. A separate native SwiftUI preview renders basic headings, quotes, bullets and task lists. Tapping a task updates its Markdown line through the same store. NoteEditor.swift
  • Local state: a main-actor ObservableObject owns the notebook, with atomic local writes, recoverable trash, Files import/export and optional password encryption. The repo also contains storage/encryption checks and a separate 500-note data-layer check.

I'd welcome code feedback on the editor bindings and language-switching approach, especially with mixed Arabic/English notes and accessibility. The preview intentionally supports a small Markdown subset rather than a complete CommonMark renderer.

The current app is free, requires iOS 17+, and has no account, ads or analytics. App Store. The internal project name remains Waraqa.


r/SwiftUI • • 4d ago

News The iOS Weekly Brief: Issue #83. Everything you need to know about SwiftUI updates this week

Thumbnail
iosweeklybrief.com
0 Upvotes

r/SwiftUI • • 4d ago

Promotion (must include link to source code) Swift95, a Windows-95 inspired components library for SwiftUI

52 Upvotes

Hey everyone 👋

I built a silly SwiftUI components library inspired by Windows95.

Built your apps or feature in a nostalgia style.

Check out it here:


r/SwiftUI • • 5d ago

Promotion (must include link to source code) built a macOS video downloader

1 Upvotes

needed to download a video and didn't really wanna deal with those random websites so i thought why not just make my own app

spent like couple of hours on it. as the name suggests it downloads videos and audio

made it with swiftui and used yt-dlp and ffmpeg for the actual downloading

here's the github if anyone wants it

https://github.com/emrecubuk/Download-FAF

there's a zip in releases, you just need yt-dlp and ffmpeg installed

if you guys have any suggestions or notice anything that could be better, let me know


r/SwiftUI • • 5d ago

Promotion (must include link to source code) [Update] Mooziac v1.2.0: native macOS menu bar app, now with a YouTube video player

Enable HLS to view with audio, or disable this notification

5 Upvotes

Hey everyone!

I shared Mooziac here a while ago. It’s a lightweight music player I’ve been building for macOS, and v1.2.0 is now out!

The biggest addition in this release is a YouTube video player, so you can switch from listening to watching without leaving Mooziac.

GitHub: https://github.com/shirkeharsh/mooziac

What’s new in v1.2.0?
A separate video window that you can switch to from the menu bar player.
Up to 4K playback, with 1080p as the default.
Hardware-accelerated video decoding for better efficiency.
Keyboard shortcuts: F for fullscreen, J/K/L to seek, [ / ] to change playback speed, and Cmd+Shift+C to copy a timestamped link.
The edge volume gesture also works while watching videos.

Other features
Built with Swift and AppKit.
Supports Apple Silicon and Intel Macs.
YouTube Music and local music in one app.
FLAC, MP3, WAV, AAC, and M4A support.
Synced .lrc lyrics and an interactive waveform.
Offline playback for downloaded tracks.
Discord Rich Presence.
No analytics, tracking, or remote logging.

Mooziac is free and open source under the MIT license. If you’re interested, feel free to check out the code, report bugs, or contribute.


r/SwiftUI • • 6d ago

Isometric Hardware with SwiftUi

Enable HLS to view with audio, or disable this notification

0 Upvotes

r/SwiftUI • • 6d ago

Built a radial launcher at the cursor in SwiftUI with a global hotkey that needs no Accessibility permission (open source)

1 Upvotes

I've been working on TactileBar, an open-source (GPLv3) macOS menu bar app with 26 system toggles and live telemetry. The latest release adds a radial launcher, and a few implementation details might be useful to others here:

Global hotkey without permissions. The ring opens with ⌃⌥Space from any app. I used Carbon's RegisterEventHotKey instead of a CGEventTap or NSEvent global monitor. It doesn't need Accessibility or Input Monitoring permission, so the user never sees a scary prompt.

Hold vs. tap on one shortcut. If you hold the key, the ring opens at the cursor and fires the slice you release on. A quick tap keeps it open for keyboard or mouse use (1–8, arrows, Return). The difference is just timing between key-down and key-up.

Everything is drawn with Canvas. The switch icons, the dial and the ring slices are all vector paths drawn in code, with no image assets. The dial packs 26 sectors plus three concentric gauges (CPU, RAM, disk).

Keeping idle CPU at 0%:

- Mach sampling (CPU and RAM) runs only while the popover is visible.

- The views are split into small u/Observable subviews, so a CPU tick doesn't re-render the whole panel.

- I removed every GeometryReader and use a fixed 540×576pt layout.

- The menu bar icons are cached as NSImage.

No dependencies. It uses only native frameworks: IOBluetooth, CoreAudio, DiskArbitration and IOKit.

Repo: https://github.com/tr0drigues/TactileBar

I'm happy to go deeper on any of these, and I'd welcome a code review of the hotkey and ring code if anyone feels like it.


r/SwiftUI • • 6d ago

Promotion (must include link to source code) NoteKit: an in-place Markdown editor for SwiftUI apps (TextKit 2, zero deps, MIT)

5 Upvotes

NoteKit is a Markdown editor for Mac and iOS built on the system text view (TextKit 2). You see the Markdown source, styled in place as you type. No dependencies, MIT, macOS 14 / iOS 17.

https://github.com/tfcace/notekit

  • Markers like # and ** step aside away from the caret and reappear when it returns.
  • Task boxes, bullets, quote bars and rules are drawn in place of their markers. Tasks tick on click/tap/⌘⏎.
  • Per-line text direction: RTL and LTR lines coexist in one note, task boxes included.
  • Obsidian syntax: wikilinks, callouts, tags, highlights, frontmatter, embeds, Templater. Unknown syntax is shown as written.
  • NSTextView / UITextView underneath, so undo, spell check, dictation and input methods just work.

r/SwiftUI • • 7d ago

Promotion (must include link to source code) Open Source SwiftUI coder editor

2 Upvotes

For those of us on Linux or Windows, it's not entirely possible to build SwiftUI apps; I'm not trying to build an Xcode for these platforms, not at all.

However, as a student or just someone exploring mobile dev, it may not make sense to go out and buy a MacBook immediately. Switaculous is a gentle introduction to Swift and SwiftUI; it's meant to be an educational tool that anybody can install and start experimenting with to learn iOS development even if you can't afford a Mac.

It's not going to allow you to publish apps, but it has good support for SwiftUI components like HStack, VStack, Text, etc., and even SwiftData.

https://github.com/kevincoder-co-za/switaculous

Fully open-sourced and MIT-licensed.


r/SwiftUI • • 7d ago

MenuBarExtra or NSStatusItem/NSPanel: which interaction requirements drove your choice?

Thumbnail
2 Upvotes

r/SwiftUI • • 7d ago

How to elongate text in swift?

Post image
4 Upvotes

How can I achieve the same thing the Lock Screen does with this particular type face, using Swift?


r/SwiftUI • • 7d ago

I found out that SwiftUI's .glassEffect(in:) takes any Shape (not just rounded rectangles).

Enable HLS to view with audio, or disable this notification

39 Upvotes

r/SwiftUI • • 7d ago

Tutorial Maths, Metal, Mandelbrot, and SwiftUI

Thumbnail
blog.jacobstechtavern.com
17 Upvotes

r/SwiftUI • • 7d ago

Question Catch-22 with App Review: rejected under 2.1(b) for not submitting IAPs, but ASC won’t let me submit more than one (FIRST_NON_CONSUMABLE_MUST_BE_SUBMITTED_ON_VERSION)

2 Upvotes

Has anyone hit this and found a way out? I’ve shipped several apps with IAPs and never seen it before.

Setup

  • A new app with its first version, 1.0.
  • 41 non-consumable IAPs: individual items plus a few bundles, one of which unlocks all content.
  • All 41 are Ready to Submit, with prices, localizations and review screenshots.

What happens

  1. I add the IAPs to version 1.0. ASC accepts only one of them.
  2. The other 40 are refused with FIRST_NON_CONSUMABLE_MUST_BE_SUBMITTED_ON_VERSION. It’s the same in the web UI and the App Store Connect API.
  3. As I read it, the first non-consumable has to be approved before any others can be submitted.
  4. So I submit 1.0 with the one IAP. App Review rejects it under 2.1(b): “the app includes references to in-app purchase products but the associated In-App Purchase products have not been submitted for review. Submit the IAPs and upload a new binary.”
  5. I appealed and explained. The next reviewer sent the same rejection, and added that IAPs are tested in sandbox and “do not need to be approved to function while in review”.

So review won’t approve the version until all the IAPs are submitted, and ASC won’t let me submit them until one has been approved through review. Neither can happen first.

What I’ve tried

  • Submitting the IAPs in the web UI and through the API: one goes in, the rest error.
  • New builds, resubmitting, and replying in Resolution Center with the exact error.
  • An App Review Board appeal.

Questions

  • Has anyone had FIRST_NON_CONSUMABLE_MUST_BE_SUBMITTED_ON_VERSION block the second and later IAPs, not just the first?
  • Did contacting Developer Support (rather than App Review) get it fixed on Apple’s side?
  • Or did you work around it, for example by shipping 1.0 selling only one bundle and adding the rest in 1.0.1?

Just to clarify, i have only seen this "bug" since ASC got updated recently with support for assets etc.

Any experience appreciated. Happy to share more detail.

EDIT: Solved, thanks everyone. It’s not a hard limit; it depends where you add the IAPs from.

  • Fails: adding IAPs to the first version from the version page, the In-App Purchases list, or the App Store Connect API. All but one give FIRST_NON_CONSUMABLE_MUST_BE_SUBMITTED_ON_VERSION.
  • Works (web UI only): open each IAP’s own page, press Add for Review, and choose the iOS draft. Then press Add for Review on the version page into the same draft, and submit.
  • If your version is stuck in an “Unresolved Issues” submission, hover over each item there for the red remove icon, take them out, and add them to the new draft.
  • Your reviewer messages stay on the old submission, so repeat anything that was already cleared in the App Review notes.