r/swift • • 4h ago

AVAudioPlayer is very laggy, am I using it wrong or should I look for another solution?

Post image
2 Upvotes

The sound is firing off every 100ms and it is causing lag in animations. Am I doing something wrong or should I look for a different way to play this audio?


r/swift • • 12h ago

Tutorial iOS 27.1: DeviceHinge

Thumbnail
antongubarenko.substack.com
0 Upvotes

r/swift • • 13h ago

Project Using Swift for scientific computing — building a nonlinear differential equation solver with Accelerate and LAPACK

Post image
17 Upvotes

I've been developing Numerical Solver, a native scientific computing application for macOS and iOS, using Swift and SwiftUI.

One of the most interesting challenges has been implementing a numerical solver for nonlinear boundary value problems.

The numerical engine combines:

  • Newton–Raphson iterations
  • Finite difference discretization
  • Symbolic computation of analytical Jacobians
  • LAPACK through Apple's Accelerate framework
  • Automatic boundary-layer detection
  • Adaptive mesh refinement

One important architectural improvement was moving from dense Jacobian matrices using dgesv_ to banded matrices using dgbsv_.

By reorganizing the unknowns and exploiting the structure of the discretized differential equations, I was able to avoid storing and solving unnecessarily large dense matrices — especially as adaptive mesh refinement increases the number of grid points around steep boundary layers.

Swift is often associated with application development, but I've found it very capable for implementing numerical algorithms as well.

I'm currently porting the updated numerical engine to the Windows version of the application, which brings its own interesting challenges, particularly replacing Accelerate.

The latest macOS version is now available.

Website: https://numericalsolver.com

I'm curious whether other developers here are using Swift for scientific computing or numerical analysis:

  • What has your experience been with Accelerate and LAPACK interoperability in Swift?
  • Have you found clean patterns for memory management and performance in tight numerical loops?

r/swift • • 20h ago

Is there a way to disable tapping on an already selected tab?

0 Upvotes

I want to prevent the double tap quirk that takes you to the top of a view.


r/swift • • 1d ago

Project Native Mobile App for Job + DSA + System Design

Thumbnail
nativemobile.org
1 Upvotes

I made an app for the iOS engineers. You can find a job listing, track your progress, learn data structures and algorithms, and find mock interview peers.


r/swift • • 1d ago

There is something I'm not understanding about @State. I'm trying to pass a boolean to a child view to stop a for loop in the child view on value change but it isn't updating the value inside the child state.

5 Upvotes

I'm new to Swift so sorry for the basic question. .onChange fires off when I change the tab, presumably updating active, but it doesn't update active in the FeedView.

Something weird is happening when I call onAppear. It is basically taking the first value it gets for active and never updating it. When .onDisappear is called it rightfully says that active is false. I also set up a ternary to change some text and it responds when active is false. Not sure what is happening.

This flashes false when I click to another tab but the loop in onAppear still prints true


r/swift • • 1d ago

Project Open-sourced Snagless: SwiftUI @Environment crashes caught at build time, using SwiftSyntax

4 Upvotes

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/swift • • 1d ago

Tutorial My Swift layout: one Xcode project, no workspace, one local package for every platform

Thumbnail
aleahim.com
6 Upvotes

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.

What I moved to: one Xcode project at the root, a thin target per platform and UI framework, and one local package with each feature as a target.

It has costs: every target resolves all of the package's dependencies, target names must be unique, and splitting features into targets changes what has to be "package" instead of "internal".


r/swift • • 1d ago

Editorial You Don’t Need ReplayKit to Mirror an iOS App

Thumbnail
soumyamahunt.medium.com
1 Upvotes

I wanted a live view of a running iOS app in the browser for a design/QA tool, with its element tree, and click-to-highlight working in both directions. ReplayKit was the obvious choice, but it means a consent dialog every session, a broadcast extension, and capturing the whole system when I only wanted my own app.

It turns out you can skip it entirely, with no consent dialog and no extension, and secure content still stays hidden.

I wrote up how it works and the trade-offs. Has anyone tried something similar?


r/swift • • 1d ago

Is there any way to play system sounds with Swift that responds to user volume (Not ringtones and alerts volume)?

7 Upvotes

I was using AudioServicesPlaySystemSound but the documentation says

"Sounds play at the current system audio volume, with no programmatic volume control available"


r/swift • • 1d ago

$50 of llm credits for $1

Post image
0 Upvotes

The pro subscription in MobileCodeAI is available for $1 today bc of Cyber Monday.

I've been using this app to build and iterate on iOS apps directly from my phone, which has been a new but great experience.


r/swift • • 2d ago

Extracted 3 SwiftPM packages from my offline web reader: zero-dep HTML5/Readability, 5-module Markdown, and a TextKit 2 reader

4 Upvotes

Over the past 12 days I built Ribbonpage, an offline Safari-to-Markdown article reader for iPhone and Mac. I just finished splitting the internal engines into three public SwiftPM repositories and wrote up the devlog.

Full write-up: https://oozoofrog.dev/blog/ribbonpage-12-day-devlog-en/

The three packages:

  1. **OozooHTML** (https://github.com/oozoofrog/OozooHTML) Pure Swift HTML5 parser, Mozilla Readability 0.6.0 port, and Turndown/GFM Markdown converter with no external dependencies. I started with a JS bundle inside `WKWebView`, but keeping JS rules and Swift tests in sync got tedious. Now `WKWebView` only snapshots the DOM (including inlining open shadow roots for sites like MDN) and `OozooHTML` handles parsing and conversion. Targets iOS 16 / macOS 13, 40 tests.
  2. **OozooMarkdown** (https://github.com/oozoofrog/OozooMarkdown) Split into 5 products (`OozooMarkdown`, `OozooMarkdownImage`, `OozooLaTeX`, `OozooCodeSyntax`, `OozooMermaid`) with no UIKit/AppKit dependency in the document model. Targets iOS 16 / macOS 13, 115 tests.
  3. **OozooReader** (https://github.com/oozoofrog/OozooReader) Contains `OozooWebReader` (WKWebView) and `OozooNativeReader` (TextKit 2). Pulling out host app concerns (custom image URL scheme, CSP, iCloud scroll-position files, translation sessions, speech synthesis, clipboard) took the most work. The manifest targets iOS 26 / macOS 26 because of SwiftUI font APIs in `OozooNativeReader` (10 tests). Both modules are read-only views, not editors.

All standalone package tests pass locally, though I have not yet verified runtime execution on physical iOS 16 / macOS 13 devices.


r/swift • • 2d ago

Three small Swift habits I use in Mac apps

12 Upvotes

Three things I keep doing in Swift, mostly in Mac apps. The last one is AppKit, because I have not found a SwiftUI modifier that does the same.

  1. Put UI work back on the main actor

If a Task does work in the background and then updates the UI, I wrap that update in MainActor:

Task {
    let data = await loadData()
    await MainActor.run {
        self.statusText = data.title
    }
}

Or I mark the type that owns the UI as @MainActor. I think this is the usual reason a label or a SwiftUI view updates late, or a warning shows up under Swift 6.

2. Use Logger instead of print

import os

let log = Logger(
    subsystem: Bundle.main.bundleIdentifier ?? "MyApp",
    category: "sync"
)
log.info("Refresh started")

In Console.app you can filter by subsystem or category. print just disappears into the system log. I would use a short static message, or be careful with interpolated values, because Logger can redact them.

3. For a floating utility, use NSPanel, not a normal window

.windowLevel(.floating) can put the window on top, but a click on it still activates your app and the other app loses the keyboard. This is the pattern that does not steal focus:

final class UtilityPanel: NSPanel {
    override var canBecomeMain: Bool { false }

    init() {
        super.init(
            contentRect: .zero,
            styleMask: [.titled, .closable, .nonactivatingPanel],
            backing: .buffered,
            defer: false
        )
        isFloatingPanel = true
        becomesKeyOnlyIfNeeded = true
        level = .floating
        collectionBehavior = [.canJoinAllSpaces, .fullScreenAuxiliary]
    }
}

.nonactivatingPanel only works on NSPanel. I still put SwiftUI inside the panel for the content.

If you have a pure SwiftUI way to get the same nonactivating behaviour, I would like to know.


r/swift • • 2d ago

News Fatbobman's Swift Weekly #164

Thumbnail
weekly.fatbobman.com
5 Upvotes

r/swift • • 3d ago

I built a native macOS IDE in Swift/AppKit, C++23, and Lua 5.4 (5.1 MB binary, 99ms cold start, local Ollama + hybrid AI)

0 Upvotes

Hey r/swift! Estou lançando a beta pública v1.0.0-beta do InelCode, um IDE nativo para macOS (Apple Silicon) desenvolvido do zero combinando Swift / AppKit na interface, C++23 (libInelCodeCore) no motor de processamento e uma VM Lua 5.4 embarcada para automação.

🏗️ Arquitetura e Destaques

  • AppKit Nativo: Interface leve e responsiva sem a sobrecarga de memória de abordagens baseadas em WebViews ou Electron.
  • Core em C++23 (libInelCodeCore): Gerenciamento de buffers, indexação e busca vetorial local via USearch, integrado a Swift.
  • Desempenho (Apple M4): Cold Start de 99.1 ms, RAM em torno de ~196.9 MB e instalador .dmg de 5.1 MB.

✨ Principais Funcionalidades (v1.0.0-beta)

  • IA Híbrida e Offline: Integração nativa com Ollama local via Bonjour ou suporte a APIs externas (Claude, OpenAI, Gemini, DeepSeek, etc.) com troca rápida de modelos.
  • Hover Semântico Universal: Exibe histórico de commit (git log), ocorrências no workspace e exemplos de uso via IA.
  • Execução Multi-linguagem: Suporte integrado a Swift, C++, Rust, Go, Python, JS/TS, PHP e Lua.
  • Segurança e Diff Inline: Visualização de alterações com aprovação obrigatória do usuário antes de modificar arquivos críticos.

🍺 Como testar

Instale via Homebrew Cask:

brew install --cask hakootunix/inelcode/inelcode

Ou baixe o .dmg diretamente em ://github.com (veja os detalhes completos da release e instruções de assinatura no repositório).

Feedback sobre a responsividade da UI, interoperabilidade Swift/C++ e estabilidade é muito bem-vindo!


r/swift • • 4d ago

Moving an existing app to Swift 6 strict concurrency: the order I'd do it in

24 Upvotes

After nine years of iOS work, the concurrency migration is the one where order matters most. Turning on Swift 6 mode in one go usually produces hundreds of errors and no idea where to start. This is the sequence that keeps it manageable:

  1. Stay in Swift 5 mode and set strict concurrency checking to "complete" first. You get the same diagnostics as warnings, so the app keeps building while you work through them.
  2. Start at the leaves. Models and small utility types are usually easiest to make Sendable. Value types with Sendable properties mostly just work. Fixing these first removes a lot of noise further up.
  3. Decide what really belongs on the main actor. View models and anything touching UI can usually be @MainActor as a whole type. That's simpler and safer than marking individual methods.
  4. Treat @unchecked Sendable and nonisolated(unsafe) as debt. They're fine to unblock a module, but leave a comment explaining why each one is safe, or they quietly become permanent.
  5. Use @preconcurrency on imports of modules you don't control, instead of fighting their missing annotations.
  6. Migrate module by module (or target by target) and switch each to Swift 6 mode once its warnings are gone. Smaller PRs are much easier to review.
  7. Watch for behaviour changes, not just compile errors. Moving work onto or off the main actor can change ordering, so test the flows that depend on timing.

What has been the hardest part of the migration for you?


r/swift • • 4d ago

I built an open-source GitHub Action that implements issues & opens tested PRs using modern Swift 6 & Xcode 27 rules

1 Upvotes

Hey everyone,

Like many of you, I've tried using AI coding assistants on iOS projects, but was constantly frustrated by:

  1. AI generating outdated iOS 14 / UIKit boilerplate instead of modern Swift 6 / SwiftUI APIs.
  2. Redundant wrapper views (like unnecessary Group { ... } wrappers or .foregroundStyle(.primary)).
  3. AI making an edit, breaking the build, and giving up.

I built PR Forge (pr-forge-ai), an open-source agent that runs in GitHub Actions or your local terminal.

When you comment /forge on an issue: • It detects the project type (SwiftPM or Xcode .xcodeproj). • Applies progressive skills: u/State macro rules, .glassEffect(), WebView/WebPage in SwiftUI, InlineArray, and functional Swift idioms. • Runs swift test or xcodebuild. • Self-audits every checkbox in your issue PRD. • Pushes a commit under PR Forge Bot and opens a PR.

We tested it end-to-end on a live macOS Swift project (Spreading Aroma), where it autonomously built a node statistics counter, code optimizer, and unit test suites that passed CI and merged cleanly.

Repo: https://github.com/shubhransh-gupta/pr-forge

What are the most annoying Swift/Xcode boilerplate patterns you'd want an autonomous agent to automate?


r/swift • • 4d ago

Question Apple Developer Academy Bali – Is it actually worth it?

9 Upvotes

Hey everyone!
I’m considering applying to the Apple Developer Academy in Bali for the next batch, and I’d love to hear some honest opinions from current learners or alumni.
I’m an international applicant and would mostly be financially supporting myself, so I’m trying to figure out whether it’s actually worth spending 10 months there.
I have a few questions:
Is the Academy actually worth it, or is it somewhat overhyped?
How much is the monthly stipend, and is it enough to live comfortably in Bali?
How much do you realistically spend per month on rent, food, transportation, electricity, and other necessities?
How much should I have saved before moving to Bali?
Is it possible to work part-time while attending the Academy, such as freelancing, remote work, or working at a café? Especially as a foreigner on a student visa.
How intense is the daily schedule? Do you have enough free time for personal projects or other commitments?
How good are the mentors and the actual learning experience?
Do you receive any Apple devices to use throughout the program?
Does the Academy actually help with career opportunities, internships, networking, or finding a job after graduation?
How is the experience for international learners? Is the language barrier an issue?
Are there any hidden expenses or things you wish you had known before joining?
Most importantly, if you could go back in time, would you still choose to join the Academy?
I’d really appreciate honest experiences, both positive and negative. I’m not expecting everything to be perfect, but since I’d be moving to another country and supporting myself financially, I want to know what I’m getting into.
Thanks in advance!


r/swift • • 5d ago

The iOS Weekly Brief: Issue #88. macOS on iPad, iOS 27.3 beta 2, unknown enum cases, Xcode MCP vs xcodebuild, SwiftUI List internals, container values, drag and drop reordering in SwiftUI, iPhone Duo layouts, and Black Friday deals

Thumbnail
iosweeklybrief.com
3 Upvotes

r/swift • • 5d ago

Tutorial Building apps is a system design exercise

Thumbnail
blog.jacobstechtavern.com
33 Upvotes

r/swift • • 5d ago

Question Starting SwiftUi and struggling to find any tutorials that actually explain where the different view elements come from and supported properties. Any books/videos I should watch as an absolute beginner?

16 Upvotes

All the videos I've seen on Youtube involve someone just randomly typing a million properties without any explanation of how they even know that an element supports these properties (e.g., how does Text() have .foregroundStyle and why does this have .white to define colour?)

Option + Click does not reveal this and I'm struggling to find anything that tells me what the properties are.


r/swift • • 6d ago

Swift package

1 Upvotes

I decided to build a swift package for using Private cloud compute and Apple's local models, I found it difficult to find the correct places to use them, and there was nothing out there to do it for me automatically, so I built my own!

Its still pretty early, it works on calibration of latency, and adjusts the model used based on request latency, it continuously re-calibrates the more its used based on the users device

Its fully open source, so feel free to check it out!


r/swift • • 6d ago

Project I built a Swift package for searching Apple's job listings

13 Upvotes

Hello all,

I recently put out a new package I've been working on to help myself learn about designing libraries. It's called JobsKit. I've been exploring the web service behind jobs.apple.com and decided to turn it into a type-safe Swift API, and figured it'd be nice if other people got a chance to try it out.

The idea behind it was to make it possible to search Apple's job listings using a Swift-based API, instead of manually dealing with the website's requests.

Here's a simple code example so you can see how it works:

import JobsKit

let client = JobsClient()

for try await job in client.allJobs(
    matching: JobQuery(text: "swift")
) {
    print(job.title)
}

You can also filter by teams, products and locations, retrieving detailed job information, and parsing compensation info where available.

It's available for all Apple platforms as well as Linux.

GitHub: https://github.com/mohalibou/JobsKit

This is my first package I've put out there, so if you have any feedback on the implementation, do feel free to let me know about it.


r/swift • • 7d ago

We rewrote the entire Rust WGPU in Swift, and it looks fantastic. I call it SAGA

Thumbnail
gallery
180 Upvotes

I've been building Ada Engine for the last 4 years, and my main problem has been finding a cross-platform SDK for graphics. I saw that Bevy and other Rust projects use WGPU, and I dreamed of rewriting it in Swift.

With AI, that day has come. In just 3 days, AI agents rewrote the entire Naga compiler and WGPU, which lets us compile WGSL (WebGPU Shading Language) to MSL (Metal Shading Language), GLSL, SPIR-V and HLSL. It all runs on-device, without vendor-specific libraries like SPIRV-Cross.

SAGA, the name of the new graphics SDK, builds and runs on Android, Windows, Web, Linux and Apple platforms. All in Swift! Ada Engine already supports it!

I'm really glad that you can now use a cross-platform graphics API in Swift instead of Vulkan or Dawn.

Check it out: https://github.com/AdaEngine/SAGA