r/swift • • Jan 19 '21

FYI FAQ and Advice for Beginners - Please read before posting

446 Upvotes

Hi there and welcome to r/swift! If you are a Swift beginner, this post might answer a few of your questions and provide some resources to get started learning Swift.

A Swift Tour

Please read this before posting!

  • If you have a question, make sure to phrase it as precisely as possible and to include your code if possible. Also, we can help you in the best possible way if you make sure to include what you expect your code to do, what it actually does and what you've tried to resolve the issue.
  • Please format your code properly.

    • You can write inline code by clicking the inline code symbol in the fancy pants editor or by surrounding it with single backticks. (`code-goes-here`) in markdown mode.
    • You can include a larger code block by clicking on the Code Block button (fancy pants) or indenting it with 4 spaces (markdown mode).

Where to learn Swift:

Tutorials:

Official Resources from Apple:

Swift Playgrounds (Interactive tutorials and starting points to play around with Swift):

Resources for SwiftUI:

FAQ:

Should I use SwiftUI or UIKit?

The answer to this question depends a lot on personal preference. Generally speaking, both UIKit and SwiftUI are valid choices and will be for the foreseeable future.

SwiftUI is the newer technology and compared to UIKit it is not as mature yet. Some more advanced features are missing and you might experience some hiccups here and there.

You can mix and match UIKit and SwiftUI code. It is possible to integrate SwiftUI code into a UIKit app and vice versa.

Is X the right computer for developing Swift?

Basically any Mac is sufficient for Swift development. Make sure to get enough disk space, as Xcode quickly consumes around 50GB. 256GB and up should be sufficient.

Can I develop apps on Linux/Windows?

You can compile and run Swift on Linux and Windows. However, developing apps for Apple platforms requires Xcode, which is only available for macOS, or Swift Playgrounds, which can only do app development on iPadOS.

Is Swift only useful for Apple devices?

No. There are many projects that make Swift useful on other platforms as well.

Can I learn Swift without any previous programming knowledge?

Yes.

Related Subs

r/iOSProgramming

r/SwiftUI

r/S4TF - Swift for TensorFlow (Note: Swift for TensorFlow project archived)

Happy Coding!

If anyone has useful resources or information to add to this post, I'd be happy to include it.


r/swift • • Nov 01 '26

What’s everyone working on this month? (November 2026)

12 Upvotes

What Swift-related projects are you currently working on?


r/swift • • 5h ago

What made you stick with Swift instead of going cross-platform?

6 Upvotes

I build iOS apps in Swift, and I keep hearing about cross-platform tools. For those of you who stayed with Swift, what kept you here? Was it the tooling, performance, or something else?


r/swift • • 9h ago

Question [UI] [HELP] ARK-OS: A Swift and Linux Based OS

0 Upvotes

Sooooo, I started this project and then i found out that the enntire directory tree was messed up so i deleted everything and started it again but this time i am going to take a step back before adding graphical interface!

Swift is a good lannguage but writing a full Swift UI will take tooo much time and also i know there are projects but still they are in alpha!

So I took a consideration:

Swift + HTML + CSS + JS... Swift for all the code ad whatever you see (the frontennde is html css and js)

But i think JS is a security risk since you never know what it does... it will not even tell you, you have to write logs for it and stuff so if you have any ideas please let me know!

P.S. I want something that dosen't use much ram so no typescript and stuff or you can suggest other langauges to!

Stack : Wayland: GTK3


r/swift • • 1d ago

Project Why I build a Swift image pipeline before opening the file

Post image
4 Upvotes

In Hokusai 1.0, Hokusai(url:) had already opened the JPEG by the time I called .resize(width: 400). The decode settings were already in place, even though the chain only needed a thumbnail. Hokusai is my Swift library for image processing with libvips, and this was one of the reasons I changed what a pipeline holds in 2.0.

I first shared Hokusai here when I used libvips for image processing and ImageMagick for text. In the next post I showed how I moved text rendering to libvips and added a CLI for benchmarks. In that discussion, u/catbrane pointed out libvips’ thumbnail path, which can shrink certain images during loading. By 1.0 I had a dedicated thumbnail API, and I wanted to use the same decoder feature for a regular resize inside a chain of operations. Original post · Follow-up · u/catbrane’s comment

What a pipeline holds now

The Swift API already returned a new value for every transformation in 1.0. Those values held native libvips images, so calls like resize() and blur() built parts of the native graph on the calling thread. Most of the pixel work could still wait until something requested the result. The library had already picked how to open the file, though, and the caller was still adding operations to the chain.

In 2.0, the Swift value holds the source and an ordered plan. A resize appends an operation to that plan, and .jpeg() sets the output options. Then data() or write(to:) hands the plan to an evaluator that opens the source and builds the native graph. libvips still computes pixels on demand, and Hokusai can see the full operation order before deciding how to decode the image.

Why the order matters

Here’s the same JPEG with the same two operations. Assume photoURL points to a 6000 × 4000 JPEG.

let source = try Hokusai(url: photoURL)

let resizeFirst = try source
    .resize(width: 400)
    .blur(sigma: 3)
    .jpeg(quality: 85)

let blurFirst = try source
    .blur(sigma: 3)
    .resize(width: 400)
    .jpeg(quality: 85)

At this point I have two plans derived from source. The try covers checks that happen while building the plans, such as rejecting a width of zero. The transforms run later. When I call data() on resizeFirst, the evaluator can read the JPEG header, see the resize at the start of the chain, and reopen the file with decoder shrink enabled. In this case, the decoder can produce a 750 × 500 image at one-eighth of the original width and height. The remaining resize brings the image to 400 pixels wide before the blur runs.

When I call data() on blurFirst, the blur needs pixels at full resolution. Shrinking during decode would change what that operation sees, so Hokusai uses the full-size decode path. Both plans produce an image 400 pixels wide. Applying the blur at different resolutions can change the result. Even with the same resizeFirst plan, pixel values can differ slightly between decoding at a reduced size and decoding at full resolution before resizing. In the first case, resize() resamples the smaller image produced by the decoder.

u/catbrane also brought up sequential access. That setting tells libvips what order to expect for pixel requests. Decoder shrink changes the size of the image the decoder produces. Sequential access remains an explicit input option. The JPEG example uses the default access mode, and the shrink decision comes from the source dimensions and the operation order.

There’s also a server-side effect. In 1.0, the Swift task assembling the pipeline could also build the native graph. Now the output call dispatches that blocking work to Hokusai’s bounded scheduler, outside Swift’s cooperative executor. The scheduler limits how many pipelines run concurrently, while libvips manages its own worker threads.

The trade-off is when errors surface. In the example, a missing file is reported when data() tries to open it. If I only need the original dimensions up front, metadata() opens the source to read its header without running the transforms.

This change made me think about how much information the wrapper has when it calls into the native library. Keeping the operation order in Swift until evaluation lets the decoder and resize work together, and callers can still write the pipeline as the same chain of operations.

If you’ve written a Swift wrapper around a native library, when do you open the native object? What trade-offs did that timing create for your callers?

Hokusai on GitHub


r/swift • • 1d ago

News The iOS Weekly Brief: Issue #89

Thumbnail
iosweeklybrief.com
2 Upvotes

Siri AI limits, App Store Awards, new iOS beta, clean projects for AI agents, if and switch as expressions, safe area, SwiftUI sheets, SceneStorage, SwiftUI co-creators Q&A, a Git client for worktrees


r/swift • • 1d ago

FYI I got a swift (inspired) tattoo

Post image
37 Upvotes

Swiftlang means a lot to me, so a natural fit for my first tattoo ^^

I wanted something that’s recognizable to fellow Swift devs, without looking too much like I have a logo on my body

Sorry to the occasional (Taylor) Swifties, I like this Swift a lot more 😂


r/swift • • 1d ago

Project I made a tool to share Swift build caches across git worktrees

8 Upvotes

I made this for personal use but I thought I'd make it available for others too.

Basically I have a 512GB Mac and I am often very close to running out of disk space on it. I switch worktrees a lot when I'm reviewing or testing changes and I end up with a separate DerivedData or .build folder for each one. I also spend a few minutes rebuilding the same deps whenever I build in a fresh worktree.

So I wrote a tool lets my worktrees share build caches, called Warm: https://github.com/theblixguy/warm-worktrees

The core idea here is to take advantage of a feature called block cloning on your filesystem. The tool uses it so copies of the build caches share disk space until their files change and only those changes occupy any additional disk space. If a dependency changes then Xcode can just fetch or rebuild what it needs and then reuse the rest.

Here's a graph to illustrate the improvements:

Now if you're using a different build system like Bazel or etc you probably don't need this tool as they already offer a shared cache feature, but I didn't want to change build systems nor want to make others do it.

This is also a general-purpose, cross-platform (macOS and Linux) tool so you can use it with Xcode, SwiftPM, etc or with other languages like Rust, TypeScript and etc so it's a single tool across all your various projects. It's highly customisable as well and can be easily integrated into your workflows, especially if you're using AI agents.

If you have any thoughts or feedback or if this tool helps you please let me know, thanks!


r/swift • • 1d ago

Our monthy CI bill went from $370 to $2,000... but we solved it with open-source

0 Upvotes

When our 4 devs went from one coding agent each to five each on our iOS app, our GitHub Actions bill went from about $410 to about $2,050 a month.

20 agents × 5 pushes a day × ~15 macOS minutes per push is 33,000 minutes a month. Most of those runs failed on things a local build would have caught in a minute: a missing import, a broken test, a SwiftLint error.

The bill wasn't the only problem. Running 300 macOS jobs a day through 5 concurrent slots (capped by GH team plan). Averaged over an 8-hour day it's ~60% of our total macOS capacity, and agents don't push evenly, so we spent more watching queues.

So we moved the checks onto our Macs. That became HAR, an open-source CLI/MCP server:

- Each agent gets its own slot: a git worktree, plus its own ports and database for our local backend. Xcode keys DerivedData by project path, so parallel `xcodebuild` runs don't collide.

- Checks live in `.har/` as plain stages (ours are SwiftLint, `xcodebuild build` and unit tests). `har env verify` runs them in a fixed order inside the slot.

- A pass is tied to the tree hash that was checked, and a commit gate rejects anything unverified, so agents can't push their trial and error to CI.

Each slot acts like a local CI runner, limited by the Mac's cores and RAM instead of GitHub's job cap. Hosted CI still runs, but only on changes that already passed locally. Our bill now <$500 after two months. First month it reduced but we were tweaking the local checks and signatures.

Works with Claude Code, Cursor, Codex or any MCP agent. Apache 2.0.

github.com/os-factory/har
`npm i -g u/osfactory`


r/swift • • 1d ago

Project Built a native macOS utility in pure Swift using IOHID, CGEventTap and CoreBrightness

Thumbnail
github.com
1 Upvotes

Hey everyone!

One thing that's always annoyed me about modern MacBooks is the lack of physical keyboard brightness keys. Whenever I'm working in a dark room, I have to open Control Center just to adjust the keyboard backlight.

So I started experimenting with using the edges of the trackpad as sliders. What started as a small personal utility eventually turned into EdgeControl.

It's a lightweight macOS menu bar app built entirely with Swift (no Electron).

What can it do?

1. Three customizable edge sliders

  • Left edge → Display brightness
  • Top edge → Keyboard backlight
  • Right edge → Volume

You can remap all three or disable them through the menu bar settings.

2. Double-tap corner shortcuts

Each of the four trackpad corners supports customizable double-tap actions, including:

  • All four macOS screenshot modes
  • Emoji & Symbols
  • Voice Dictation
  • Spotlight
  • Sleep Display
  • Media controls
  • Mission Control
  • Show Desktop
  • Lock Screen
  • Dark Mode toggle

3. A few things I spent extra time getting right

  • Cursor freeze while sliding, so your pointer doesn't travel across the screen.
  • Palm and wrist rejection to prevent accidental triggers.
  • Typing cooldown to avoid unwanted bottom-corner actions while typing.
  • Native macOS brightness and volume HUD bars using low-level system APIs, with a custom SwiftUI fallback.

Technical details

  • Pure Swift
  • Approximately 1,715 lines of code
  • Around 1.8 MB zipped
  • MIT License
  • No Electron or background web processes

Requirements & installation

  • macOS 15+
  • Apple Silicon MacBook with a Force Touch trackpad.
  • Accessibility permission for native HUDs, cursor freezing and shortcuts.
  • No Screen Recording permission required.

Since I don't have a paid Apple Developer ID, the prebuilt release is ad-hoc signed. After moving the app into Applications, you'll need to run:

xattr -dr com.apple.quarantine /Applications/EdgeControl.app

Links

GitHub: https://github.com/Niru-26016/EdgeControl

Latest Release: https://github.com/Niru-26016/EdgeControl/releases/latest

I'd genuinely love to hear what other actions you'd find useful on the trackpad edges or corners.

Also, if you try it out, let me know how it works on your MacBook. Feedback, bug reports and contributions are welcome!


r/swift • • 1d ago

Reading raw trackpad touches on macos without the touch arriving as a scroll first

0 Upvotes

been building a mac menu bar app (gesturely) that does custom trackpad gestures, and the hardest part wasn't the gestures, it was telling a real swipe apart from a palm or a resting thumb.

a few things that ended up working for me:

measuring everything in millimetres instead of normalised coordinates. a swipe fires after 12 mm of travel in any direction, so up/down and left/right feel the same, which they didn't when i used fractions of the pad (the pad is wider than it is tall).

palms are easy once you look at contact size. anything with a major axis around 30 mm or more gets ignored.

resting thumbs were annoying. what works is: landed in the bottom quarter of the pad, been down for half a second, barely moved. then it doesn't count as a finger, so a two finger scroll with your thumb resting doesn't turn into a three finger swipe.

also learned the hard way not to allocate anything in the touch callback. it runs every frame, and after cleaning that up the recognizer takes under 70 ns per frame.

has anyone else played with raw touch data on mac? or found a cleaner way to deal with thumbs?


r/swift • • 1d ago

Project Open Source Thursday

Post image
1 Upvotes

I was too busy to do this on Tuesday, so it's open source Thursday.

These are just a couple of tools that I built (disclosure: with Claude Code) because I needed them. Not because of anything else.

Hopefully, they will be useful to other folks. Source code + tools.

First tool is FolderDrill (on Github at ancientcomputing/folderdrill). This very simple app helps me drill into my filesystem to understand why (on a 1TB Mac Studio) I have less than 50GB left of free disk space. Since I mostly work on local AI, I download a lot of open weight models from Hugging Face. Problem is that ~/.cache is not the only place where downloaded models live. When testing sandboxed apps, the downloaded models live in the sandbox! The question is where exactly (after several months of testing various things). So thanks to this tool, I now have >200GB left of free space. I'm sure that the Mac App Store has similar tools, but I couldn't find one quickly ...

The second tool is Model Shelf (ancientcomputing/modelshelf). This one is a little more specialized and more useful for folks (like me) who live/breath open weight models. If FolderDrill doesn't help you manage disk space sufficiently, you (like me) probably have too many models downloaded in ~/.cache. So Model Shelf helps me manage a library of models sitting in an external drive and move them back/forth fron the Mac Studio or my MBA.

Voila! Let me know if I'm missing anything in terms of best practices/security/usability etc.


r/swift • • 2d ago

More information needed on non-Gregorian calendars implemented in Apple OSs

3 Upvotes

This is going to be different.  Usually when discussing programming, we love to talk about cool things we can create.  I’m going to ask about a big hole in the documentation that no one seems to have realized was there but programmers around the planet should be able to at least partially fill in.

I have a personal programming project, Date-O-Rama, is a date/time program which does things which Apple’s code doesn’t.  One of the major issues is that Apple assumes that every calendar system starts every day at midnight, and one of the earliest things I did was coerce the Hebrew calendar to start the new day at the right time:  Sunset.  I also made the Hebrew calendar support Solar time, with the day and night each divided into 12 hours.  I applied both of these features also to the Islamic and Bahá’í calendars (the latter based on non-Apple code), as they are both Sunset-day-start calendars to the best of my knowledge.

Thing have gotten more complex since Apple implemented 11 new calendars in the past few years.  Two of them, Dangi and Vietnamese, seem closely related to the Chinese calendar.  The rest (Vikram Samvat, Bangla, Malayam, Tamil, Odia, Gujarati, Kannada, Marathi, Telugu) are all clearly related to each other.  I have all these calendars up and working in Date-O-Rama, but I’m not clear I have everything done the right way, so I’m asking the planetary programming community to fill in details which an outsider like me would generally not know.  And since I’m reaching out, I’m going to ask about the calendars implement by Apple in general.

  1. At least some of the calendars from the Indian subcontinent, e.g., Vikram Samvat, have the day start at Sunrise instead of midnight.  Is this true of all the Indian subcontinent calendars?  I’m also aware that some of these calendars divide the lunar month into 30 tithis, which are not of equal length.  How does this affect when people consider the day to begin?
  2. Do days of the week apply to tithis?
  3. How are all these Indian subcontinent calendars related?  Wikipedia reports that there are two views on when months start (right after full Moon and right after new Moon) and that a lot of these calendars actually come in both lunar and solar versions, even though only one is implemented (or at least accessible via Apple’s API).  In some cases, the only difference between calendars looks like different eras (Vikram Samvat versus Saka), and the Gujarati calendar looks like it could easily be the Vikram Savat calendar with the alternate starting point of the month.  And are any of these calendars the lunar or solar variant of another calendar?
  4. What are the differences between the Chinese, Dangi, and Vietnamese calendars?  Wikipedia reports that the Vietnamese calendar doesn’t always have intercalary months when the Chinese calendar does.  Dangi looks like it might be just the Chinese calendar with a different year numbering.
  5. When is the day supposed to begin on the Chinese, Dangi, Vietnamese, Coptic, and Ethiopic calendars?
  6. My impression is that the Coptic calendar may be identical to the Ethiopic calendars except for a different year numbering and month names.  Is this correct?
  7. Apple implements four separate Islamic calendars.  Which countries actually use them?
  8. How do calendars working on Solar time divide up the day and annotate time?  (I have the Hebrew calendar dividing days and night up into 12 hours each, but I have no a priori reason to think all calendars work this way.)

Thanks in advance for any help anyone can provide.


r/swift • • 2d ago

Built a VM lab tool on Virtualization.framework and the new vmnet APIs: lessons learned

2 Upvotes

I wanted a network lab on my Mac that feels native: no QEMU, no Docker, no background daemon. So I built vz in Swift on top of Apple's own frameworks:

  • Virtualization.framework for the VMs
  • vmnet (the new macOS 27 network APIs) for virtual switches with NAT and DHCP
  • DiskImageKit for copy-on-write disks, so every node boots from its own overlay of a shared image
  • Plain socketpairs as cables between VMs, which you can unplug and replug while they run

The result is quick. Two routers with their switches and cables come up in under half a second (the screenshot shows 499 ms), and vz link down cuts a cable instantly.

Dependencies: swift-argument-parser and Yams. Tests use swift-testing. macOS 27 only.

https://github.com/rayanparsa/vz

Code review and criticism welcome.


r/swift • • 2d ago

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

Post image
9 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 • • 3d ago

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

Post image
28 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 • • 3d 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.

6 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 • • 4d 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 • • 3d ago

Tutorial iOS 27.1: DeviceHinge

Thumbnail
antongubarenko.substack.com
0 Upvotes

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

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

Thumbnail
soumyamahunt.medium.com
3 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 • • 3d 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 • • 3d 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.