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 • • 20d ago

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

12 Upvotes

What Swift-related projects are you currently working on?


r/swift • • 11h ago

Chord: a free, open-source macOS app for iOS devs working with coding agents

6 Upvotes

When I work on iOS apps with AI agents, I can get a lot done in parallel. The problem was that the agents kept building over each other, and I couldn't run builds or check previews on different branches at the same time.

I also hate having a lot of apps open at once like sourcetree, Xcode, finder, the Simulators and so on. Chord puts all of that in one window. It's now the app I use every day. You can bring your own harness (pi, Claude Code or Codex), run builds and simulators for each branch, and check every SwiftUI preview from a list.

https://github.com/Pistifeju/Chord

It's free and open source, and still in early development.


r/swift • • 19h ago

Project Mference 2.0: Native Swift 6.1 + Metal 3 MoE LLM runtime (18.36 tok/s on Qwen 3.6 35B in 16 GB RAM, zero Python in inference)

Thumbnail
gallery
6 Upvotes

Sharing Mference 2.0 (Apache-2.0 / MIT, forked from NeelM0906/Mference & derived from drumih/turbo-fieldfare) — a native Swift 6.1 + Metal 3 + SwiftUI + SwiftNIO local LLM runtime running Qwen 3.6 35B-A3B (INT4, 256 routed experts) comfortably on a 16 GB Mac.

Swift + Metal Highlights

  1. Custom Metal Kernels + LMHeadChainInt4**:** Batched epilogues (PrefillQKVEpilogue), custom INT4 MoE routers (MoE.encodeRouterGemma4), and exact within-8-row-group top-2 EVICT logit-margin summaries in logit.metal.
  2. MTP Speculative Verify over Gated-DeltaNet + KV: Captures a 4-slot GPU rollback arena (Qwen36MTPSpeculator) and pipelines commitAcceptPass while staying bit-exact with greedy decode (83.1% accept rate, 94.3% AIME, up to 18.36 tok/s).
  3. Bounded Memory + SwiftNIO Server: PreadExpertStreamer with prefill-tail warm start (32 NVMe cache slots), POSIX_MADV_RANDOM slab-only MTP mapping, 2-slot LRU ServerPromptCache, :8080 OpenAI API server, and SwiftUI MferenceMac app.
  4. In-Place BF16 Weight Surgery (MferenceRepack): Scales group-64 affine scale/bias tables (w = s*q + b) atomically in model_weights.bin (0 INT4 nibbles modified), lifting 8-task Pass@1 from 25.0% (2/8) to 100.0% (8/8).

Everything builds via swift build -c release / swift test on macOS 15+!


r/swift • • 1d ago

Anyone using Claude Code with Swift 6.2 lately?

6 Upvotes

Hey folks,

Is anyone here using Claude Code for work? I remember at the start of the year it struggled to understand Swift 6.2's parallelism and concurrency concepts. I was really disappointed and ended up fixing a lot of things manually.

What’s the situation like today?


r/swift • • 1d ago

What should I be learning as a beginner, SwiftUI or UIKit?

22 Upvotes

I literally just started a few days ago and apparently you can't do basic things like reference, identify or modify subviews while the app is running with SwiftUI? I just want to add infinite scroll and I had a hacky solution that doesn't work with SwiftUI. So my question is what should I be learning if I want to make apps as a solo dev?


r/swift • • 1d ago

Running an async call only once on load ?

5 Upvotes

So I have a tab view where for the content of each tab has a view that takes a string containing what type of content it is going to display. I want to get info from my server only once instead of calling it every time when switching tabs. I'm currently using .task and I'm wondering what i could use to have an async call happen only once on load in. I tried init but for some reason it messed up being able to pass a string to the view as an argument

any help would be appreciated.

Solution:

Found this solution from Gabriel Tondin

struct MyView: View {
    let store: StoreOf<MyFeature>
     private var hasAppeared = false

    init(store: StoreOf<MyFeature> {
        self.store = store
    }
    
    var body: some View {
        WithViewStore(store, observe: { $0 }) { viewStore in
               // content
                .onAppear {
                    guard !hasAppeared else { return }
                    hasAppreared = true
                    viewStore.send(.onAppear)
                }
        }
    }
}

r/swift • • 1d ago

How do I get a specific subview, delete a specific subview, and add a specific subview?

2 Upvotes

Is there something like self.body.subview to get a subview?

Is there something like .append to add a subview?

Is there a self.body.subview.delete()

Can I add ids to subviews?

New to swift. I found insertSubview but for some reason it says it can't find it in scope when I try to execut it.


r/swift • • 1d ago

News The iOS Weekly Brief: Issue #87. App Store Award, migrating to Swift Testing, context menus in SwiftUI, ReservedRegion for iPhone Duo, senior iOS interview, scroll position, scroll-driven effects, and Vision with Foundation Models.

Thumbnail
iosweeklybrief.com
2 Upvotes

r/swift • • 3d ago

Project I benchmarked my Swift memory library against the standard AI memory benchmarks, then spent weeks fixing it. Here are the before/after numbers.

7 Upvotes

I build Wax (https://github.com/christopherkarani/Wax). It’s a local memory store for AI agents and on-device models, written in Swift. Everything lives in one .wax file: documents, an FTS5 text index, Core ML vectors and a WAL. Claude Code, Codex and Cursor connect to it over MCP, and Apple Foundation Models get it as on-device tools. 0.1.51 shipped this week.

I spent the last few weeks running Wax against the standard memory benchmarks. The early numbers were bad, so most of the work went into fixing Wax. Every number below comes from the harness in the repo, and the scripts to reproduce it are there too.

Before and after (100k passages, M3 Max, importDocuments store):

BeforeAfter
Disk13.5 GB286 MB
Ingest136 docs/s57,250 docs/s
Vector search p9564–97 ms1.55 ms (p50 1.05 ms)
Cold open + first query840 ms108 ms
Recall@10 vs exact search0.9020.998

Retrieval quality:

  • LongMemEval-S: R_all@5 of 0.938, against 0.902 for Contriever (a 110M-parameter retriever).
  • LoCoMo: R_all@5 of 0.609, against 0.407 for Contriever. Before the fixes it was 0.186.
  • That’s with e5-small-v2 (33M parameters) and a 22 MB MiniLM cross-encoder reranker. Both ship as Core ML models computing in FP16 over INT8 weights, and both are on by default.

Against mem0 on LoCoMo QA: I ran open-source mem0 through the same reader, judge and scoring. Given the same amount of context (about 16.8k characters, which is Wax’s top 98 turns), Wax scored 77.7% and mem0 77.5%. To build its memories, mem0 made about 6,000 LLM calls at ingest. Wax made none: you store a sentence and hybrid search finds it later. The gap is within noise, so I’m calling it a tie, not a win.

The Swift API

The public surface is one actor, Memory. You open a file, save text, and search:

import Wax

let url = URL.documentsDirectory.appending(path: "agent.wax")
let memory = try await Memory(at: url)

try await memory.save("The user is building a habit tracker in SwiftUI.")
let results = try await memory.search("What is the user building?")
if let best = results.items.first {
    print("Found: \(best.text)")
}

try await memory.close()

On iOS 18 / macOS 15 and later, Memory(at:) loads the e5 embedder on its own; there’s nothing to configure. Search is hybrid by default: text and vectors fused, then reranked. Every result carries diagnostics, so you can see whether a query actually used vectors or fell back to text while the model was still loading. For bulk loads there’s importDocuments, which is where the 57k docs/s comes from. It’s atomic: if it throws or the app crashes, the store is left as it was.

Foundation Models

Apple’s on-device LanguageModelSession forgets everything between launches. Wax gives it a memory that survives restarts. One call gets you a session that recalls relevant memories into the prompt, has remember/recall/search tools, and can write turns back:

let memory = try await Memory(at: url)
let session = memory.foundationModelsSession(
    instructions: "You are a helpful assistant with durable on-device memory."
)
let answer = try await session.respond(to: "I prefer dark mode and Vim keybindings.")

If you already have your own session, just attach the tools:

let tools = memory.foundationModelsTools(kit: .focused)
let session = LanguageModelSession(tools: tools) {
    "You have long-term memory via waxRemember / waxRecall / waxSearch."
}

The model, the embedder, the reranker and the store all run on the device, with no network calls.

If you want to try it, add the package (https://github.com/christopherkarani/Wax.git, from 0.1.51), or run npx -y waxmcp@latest install to use the MCP server with Claude Code, Cursor or Codex. I’d love feedback, especially from anyone shipping on-device AI in Swift.


r/swift • • 2d ago

Help! Title: Swift Playgrounds not working properly on iPad – Prewarm failed, black screen and downloads not working

1 Upvotes

Hi everyone,
I’m having several issues with Swift Playgrounds on my iPad, and I’m trying to figure out whether this is a known bug or something wrong with my device.
I’m developing a native SwiftUI app (App project) for iPad, but I’m unable to run it.
Here are the problems I’m experiencing:
When I try to run my project, I get a “Prewarm failed” error saying that the app doesn’t have permission to save CurrentUser.txt in its Documents folder.
The console shows no error messages at all.
I created a completely new App project using the default template, without changing any code, but it only displays a black screen.
The “Learn to Code” section also fails to download its content.
I’ve already tried restarting the app and testing with a completely new project. The problem persists.
This makes me wonder whether the issue is related to a recent Swift Playgrounds update or an iPadOS bug.
Has anyone experienced something similar?
Is there a way to install an older version of Swift Playgrounds, or is there any known workaround?
I’d really appreciate any help. Thanks!


r/swift • • 2d ago

vibe coded a spotify menu bar player in swiftui. apple events instead of the web api

0 Upvotes

i'm a developer and wanted a spotify mini player for myself, so i vibe coded one. swift is not my daily language, so the interesting part for me was how it ended up talking to spotify.

  • it uses the desktop app's applescript dictionary. no oauth, tokens or rate limits.
  • spotify posts `com.spotify.client.PlaybackStateChanged` when the track or play state changes. the app reads state on that notification, with a slow timer as fallback for missed ones.
  • the cost is the automation permission prompt and no app sandbox, which rules out the app store.
  • the permission is tied to the code signature, so every release is signed with the same certificate to keep it across updates.

source, mit: https://github.com/Abulkosim/tonearm


r/swift • • 3d ago

Question App testing in Testflight or App Store

4 Upvotes

Getting ready to release my first iOS app and will be looking for people willing to test it.

Generally do I ask them to test using TestFlight or do I need to have it on the APP store?

I will expect some bugs and feedback so I am prefer using TestFlight.

Comments or suggestions are appreciated.


r/swift • • 3d ago

Some tips for the Swift Student Challenge 2027

2 Upvotes

I am taking part in this years challenge where the size limit is 500 mb. One thing that i wanted to ask is that should the judged be able to understand the core idea of our the project/ 4pp(reddit is stupid) in under 3 minutes or that they should be able to visit every inch of the 4pp within 3 minutes. My 4pps core idea could be understood in 3 minutes but visiting every inch of the 4pp, that might not be possible. Any suggestions would help a lot. any other tips for the challenge as a whole from experienced participants, winners or distinguished winner would be even more help ! thanks
Just a question how much AI is okay and how much is just not because in 2026 AI can make better things than someone who started learning siwft 3 months ago(me)


r/swift • • 4d ago

Anyone else building Swift apps just to solve random everyday problems?

71 Upvotes

I've been building a little Swift app to keep track of my vegetable garden. Nothing fancy, just UIKit and Core Data. I can map out my beds, move crops around, and log harvests.
Started it because I kept forgetting what I'd planted where and somehow always ended up putting tomatoes in the same spot lol. My wife suggested a spreadsheet, but I figured making an app would be more fun.
It's all local for now, but I'm thinking about adding iCloud sync so we can both use it. Maybe a simple widget for reminders too.
Anyone else using Swift for random personal projects that have nothing to do with the App Store? Curious what you've built and whether you actually finished it or it's still sitting at 80% like half my other projects lol.


r/swift • • 4d ago

I built an open-source tool that gives SwiftPM a single global APFS store across all projects and worktrees (like pnpm for Swift)

15 Upvotes

If you work on multiple iOS/macOS apps, client repos, or Git worktrees (especially with AI coding agents spinning up branches), you have probably noticed what happens to your disk and build times:

Every workspace path gets its own DerivedData/<App>-<Hash>/SourcePackages folder. Have 4 projects or worktrees using firebase-ios-sdk, stripe-ios, grpc-swift, or swift-syntax? You download, checkout, and store the exact same gigabytes four times.

I built spmx (open source, MIT) to fix this without changing how you run Xcode, swift, or xcodebuild.

How it works

  1. One global store (~/.spmx/store): Stores each (package, version) checkout, binary XCFramework artifact, and Swift macro prebuilt once, alongside shared bare Git repositories. Different projects keep their exact Package.resolved versions without forcing upgrades.
  2. Zero-copy APFS hydration: Lightweight PATH shims for swift, xcodebuild, and flutter clone matching packages from ~/.spmx/store into your project's SourcePackages using macOS APFS clonefile(). It takes milliseconds and uses zero additional physical disk blocks.
  3. Shared LLVM CAS compilation cache: Configures ~/.spmx/compilation-cache when supported by your toolchain so clean builds across worktrees share compiler outputs.
  4. Retroactive deduplication (spmx link): Run spmx link to scan your existing DerivedData and project folders across your Mac. It prints the full plan and estimated GB saved before asking for confirmation to replace duplicates with APFS clones.

Benchmarks (Apple M4 Pro, swift-composable-architecture fixture)

  • Warm package resolution in a new worktree: 42.3s (native) -> 0.46s with spmx hydrate
  • Extra physical disk per worktree/project: ~0 MB (shared APFS blocks)

Current limitations (what is still rough)

  • macOS 13+ on APFS only: No Linux support since it relies on clonefile() and DerivedData layout.
  • Xcode GUI doesn't read shell PATH: If you build strictly via the Play button in Xcode GUI instead of CLI, you need to enable the opt-in Git hook (spmx hooks enable --global) so packages hydrate on git checkout / git worktree add, or run spmx link.
  • SwiftPM only: It does not deduplicate legacy CocoaPods (ios/Pods).

Try it

curl -fsSL https://get.spmx.io | sh
spmx setup
spmx link

(Or via Homebrew: brew install LuisRibeiroo/tap/spmx)

If you want to exclude a specific repo from the global store, run spmx unlink <path>.

  • GitHub: https://github.com/LuisRibeiroo/spmx
  • Website & Benchmarks: https://spmx.io/benchmarks

Would love feedback from anyone juggling multiple Swift repos or worktrees, especially if spmx link hits any edge cases on your DerivedData setup.


r/swift • • 3d ago

News I built Snitch, an open-source in-app inspector for network requests and analytics events (PostHog, AppsFlyer)

0 Upvotes

Hey r/swift,

For the past few weeks I've been working on a side project and wanted to share it here for feedback.

Snitch is a debugging tool you add to your iOS app. It shows every network request and every analytics event your app sends, right on the device. Shake the phone (or tap a floating button) and you get a timeline you can search and filter.

Why I built it: at work I kept asking "did that analytics event actually go out, and what was in it?" Answering that meant print statements, setting up a proxy, or staring at gzipped and encrypted payloads.

What it does:

- Captures URLSession traffic via URLProtocol, with headers, pretty-printed JSON bodies, search and filters
- Works with your own URLSessions and keeps their settings, so cookies, caching and SSL pinning still behave normally (auth challenges are forwarded to your session's delegate)
- PostHog events through its beforeSend hook, and each event links to the batch request that uploaded it (Snitch unzips the gzip body and matches event IDs)
- AppsFlyer events with zero code changes: it finds the SDK at runtime and wraps its public logEvent methods, so there's no AppsFlyer dependency
- Copy as cURL, pause recording, light and dark mode, Liquid Glass on iOS 26 with a fallback to iOS 16
- Debug-only: every call is a no-op without DEBUG, and nothing leaves the device

The core has zero third-party dependencies. Setup is one line: Snitch.start()

GitHub: https://github.com/BachoOnn/snitch

I also shared the story behind it on LinkedIn, with a few slides showing it in action:
Linkedin post

It's still early, so I'd really appreciate feedback, bug reports, or ideas for which SDK to support next (Firebase? Mixpanel?). Happy to answer questions about how any of it works.


r/swift • • 4d ago

Help! Glass background widgets

Post image
21 Upvotes

hey friends, coming to you after spending days trying to figure out how on earth muse & chatgpt pulled off the glass background on their widgets because as far as apple’s docs are concerned, liquid glass rendering is entirely delegated to the system, and on paper, widget glass comes from the home screen’s clear and tinted styles but these are working in default and dark styles

HOW???


r/swift • • 3d ago

SwiftExoPlayer

Thumbnail
github.com
1 Upvotes

I’ve been working on SEPlayer, a framework for building media players with almost all playback logic running entirely in userspace. Only decoding, video rendering, and audio playback are handled by the system.

I’ve spent two years researching and experimenting with different playback pipelines. Initially, I followed ExoPlayer’s approach, but its high-frequency timer-based pipeline isn’t particularly power-efficient.
I think I’ve finally found a better solution: an event-driven pipeline that only does work when necessary.
The project is still in alpha, and there’s a lot left to implement.

Currently supported:
Progressive MP4, fMP4, and MPEG-TS playback
HLS

Planned:
MPEG-DASH
Additional containers and formats, including Matroska, AVI, MP3, and raw AAC streams
More stability improvements, error handling, and tests

One of the main goals is extensibility. Unlike AVPlayer, SEPlayer allows you to implement your own demuxer, use different renderers, or replace the ABR algorithm, much like ExoPlayer.

There’s still a long way to go, but I wanted to share what I’ve been working on.
I’d be interested in hearing feedback, especially from anyone who’s worked on media playback pipelines or video players.


r/swift • • 3d ago

Tutorial Choosing a DB is More Nuanced Than You Think

Thumbnail
medium.com
0 Upvotes

r/swift • • 4d ago

What is the equivalent to a HTML div in swiftui?

13 Upvotes

I want to separate specific groups of items in a HStack without applying spacing to all the items. New to Swift


r/swift • • 4d ago

Project DoomMail: Another project on opensource

Thumbnail
gallery
0 Upvotes

I'm a fan of doomscrolling, so in addition to the DoomSurf project that I've published on the iOS App Store, I built a DoomMail project which I am opensourcing. It's on github at ancientcomputing/doommail-oss . Let me know if y'all want the full URL.

The concept of DoomMail is that rather than have an eye chart of emails on your email app, each email resides on its own card and you doomscroll through the email cards. I am old enough to remember email clients in the 1990s and the basic list of emails have not changed. At all.

I used Apple Intelligence (aka the on-device model, for privacy/security) to summarize each email for the card, it's only when you tap on the card that you can read the whole email. There are additional actions that you can take like reply, delete, star, archive the email. Feel free to guess what the rabbit icon is about 🤫

One thing I had to workaround was dealing with the "censorship" that the on-device model practices e.g. it will refuse to summarize some emails because of what it deems to be "sensitive" topics in the email.

I personally think that this is potentially useful as the basis for a new type of UI/UX paradigm, but don't want to go further with this. Currently, this supports Gmail. However, you do have to go through some hoops to enable it. Fully documented in the /docs folder.

In addition, if you do want to make this available beyond TestFlight e.g. actually publish this in the App Store, you have to jump through a bunch of Google-mandated security approvals (and pay a yearly fee). So as an indie project, it may not be useful. However, please feel very free to take this and run with it. Maybe at least use a friendlier name...! 🤓


r/swift • • 5d ago

Tutorial iOS 27.1: ReservedRegion

Thumbnail
antongubarenko.substack.com
5 Upvotes

r/swift • • 5d ago

News Fatbobman's Swift Weekly #162

Thumbnail
weekly.fatbobman.com
10 Upvotes