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

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

12 Upvotes

What Swift-related projects are you currently working on?


r/swift • • 3h ago

Project Built a full Google Maps app for Apple Watch with Claude Code: real Google tiles, search, traffic directions, turn-by-turn on the wrist

1 Upvotes

So I've been annoyed for a while that Google Maps on the Apple Watch is basically a remote control for the iPhone app. No map you can actually browse, and you start everything from the phone. On Android watches it's way better. Apple Maps just isn't as good where I live.

So I decided to build my own, and I did pretty much all of it with Claude (Claude Code, in my terminal).

What it does

  • Actual Google map tiles on the watch (standard, satellite, terrain, dark), with traffic/transit/biking layers. Digital Crown zooms, drag to pan, long-press to drop a pin.
  • Google search with autocomplete. Results have ratings, hours, open/closed, reviews, phone numbers.
  • Search results show as a card at the bottom with ◀ ▶ arrows, so you can flip through "coffee near me" one place at a time and the map flies to each one. Way easier than scrolling a list on a tiny screen.
  • Google directions with live-traffic ETAs for driving, walking, cycling and two-wheeler. Transit times come from Apple Maps, because Google won't serve transit routes outside a browser.
  • Turn-by-turn navigation:

    • The turn is a small green chip in the corner ("↱ 40 m") so it doesn't cover the map. Tap it to expand the full card.
    • Turn the Crown for the list of upcoming steps, and again for a page of big buttons (voice, haptics, overview, share ETA, end).
    • Different haptic patterns for left and right turns, so you can tell which way to go without looking. Right is a steady run of taps, left is taps in pairs.
  • One tap to switch voice between on, alerts only and muted. It remembers your choice.
  • If the app gets closed mid-route, reopening it asks "Resume route to X?"
  • Complications, Siri shortcuts ("take me home with Wayfinder"), parking spot saving with a meter timer, trip timeline, compass.

No API key and no iPhone app needed. It talks to Google the same way the Google Maps website does.

Caveats, to be upfront

Unofficial, not affiliated with Google in any way.

  • It uses Google's undocumented web endpoints, so it could break any day if Google changes something, and it's probably against their ToS. Personal/educational use.
  • Not on the App Store. You install it yourself with Xcode; a free Apple ID works. The README walks through it step by step.
  • Needs watchOS 26+. I've tested it on my SE 3 and in the simulator.

Repo with a demo video: https://github.com/GagnDeep/google-maps-for-apple-watch


r/swift • • 1d ago

From UIKit and Storyboards to SwiftUI and Android via Skip

Post image
9 Upvotes

Hey everyone! 👋

Over the past year, I brought my app Budget Flow to Android using Skip while modernizing its existing UIKit- and Storyboard-based interface with SwiftUI.

For those unfamiliar with Skip, it's an open-source framework that enables developers to build native apps for both iOS and Android using Swift and SwiftUI from a shared codebase.

As a solo developer working on the app alongside my full-time job, my goal was to share as much code as possible across platforms without sacrificing the native user experience or existing platform-specific integrations. Since Budget Flow has been in users' hands since 2023, preserving their data and existing features was equally important.

To help other developers considering a similar migration and share some insights from my experience, I've written an article about my journey. It covers why I chose Skip over other cross-platform frameworks, provides an overview of the new architecture, and discusses platform-specific integrations and performance challenges, as well as lessons learned along the way.

You can read the full article here: From UIKit and Storyboards to SwiftUI and Android via Skip

The modernized version has been available on the App Store for about a month, and the Android public beta is now available on Google Play.

I'd love to hear your thoughts and would be happy to answer any questions! 😊


r/swift • • 1d ago

Distributed actors over HTTP, now playing in a browser near you

Thumbnail
treasure-hunt.examples.elementary.codes
9 Upvotes

Did you know Distributed now works in Embedded Swift (on main)?

I put together a small library, actor-rpc, that turns Swift distributed actors into plain HTTP calls. You write a protocol, the server implements it as a distributed actor, and a client calls it like any other async function. The client can be anything, including an Embedded Wasm app in the browser (like the Treasure Hunt game).

// Shared
@Resolvable
public protocol TreasureHunt: RPCService {
    distributed func newGame(size: Int) async throws -> Game
    distributed func dig(_ cell: Cell, in game: Game) async throws -> DigResult
    distributed func reveal(_ game: Game) async throws -> Cell
}
    
// Browser
let transport = RPCHTTPTransport(executor: FetchExecutor(), options: .init(basePath: "/rpc"))
let hunt = RPCClient(transport: transport).resolve($TreasureHunt.self)

let result = try await hunt.dig(cell, in: game)

A few things I cared about:

  • Boring on the wire. Each call is a JSON POST, so your load balancer, CDN, gateway, observability, etc. don't need to know anything special. The demo runs CloudFront → API Gateway → Lambda.
  • Bring your own server. The server side is one call in your HTTP handler: Vapor, Hummingbird, whatever. The demo uses a bare Lambda handler.
  • KISS. Just a client talking to a server with a Swift protocol as the API. No cluster, no membership, no gossip, no codegen, no YAML.

It's a very early proof of concept (needs a main toolchain and the experimental NewCodable branch), so expect things to move. What do we think?


r/swift • • 22h ago

Swift Student Challenge will start soon with events in December

Thumbnail
developer.apple.com
1 Upvotes

All winners will receive one year of membership in the Apple Developer Program and a special gift.


r/swift • • 16h ago

Question Would you be able to tell what my Swift package is for, and whether you'd use it?

0 Upvotes

For anyone who hasn't come across it, I maintain the LocalLM SDK (formerly the LocalLM Lab SDK), for building native Swift Mac apps with AI features. An app can use Apple's on-device model, Private Cloud Compute, open-weight MLX models, or GPT and Claude. Version 3.0 just went GA. I could go on about what's new, but what I'd like to check here is the user journey for a new developer: can someone who hears about the SDK tell quickly what it is and whether it's for them?

I spent some time improving the getting-started experience for 3.0. There's now a landing page, a README on GitHub with a screenshot, a new 50-line quickstart chat written for people new to AI, about twenty examples, and a free Mac app to try things before writing code. Even so, I recently watched an AI agent cold-read (that's apparently a "thing" these days!) the site and come away wrong about which models are supported, which made me wonder whether people do too.

If you have two minutes:

  • Would you end up on the website or GitHub first? And once there, could you tell what this is without scrolling?
  • What would make you actually try it? Or what would make you close the tab?
  • Is a 50-line chat app example using Apple's on-device model a good place to start, or is it jumping into the deep end too quickly?

Site: thisbrain.ai/locallm · GitHub repo at ancientcomputing/locallm


r/swift • • 1d ago

Question tvOS "covr" artwork, can I include more than one aspect?

0 Upvotes

I am developing an app that uses AI to figure out what the media is from the filename along with other "nearby" resources like any text files or the metadata in the file. It then goes to TheTVDB and downloads the artwork.

My question:

The artwork is generally available in three forms, "poster" which is 2 wide by 3 tall, "background" is 16 by 9, and "icon" is 1 by 1.

Does anyone know if it's possible to include more than one image in the covr, and if so, how do I annotate it so the user sees the one they selected?


r/swift • • 1d ago

Help! I have a question about Xcode

0 Upvotes

Unfortunately, i don’t have a MacBook, but I’m learning iOS development (SWIFT) and i need to use Xcode. Are there any way to use all apple features on the windows? I wanted to install macOS on virtual box and use Xcode in this virtual machine, is that even possible? Let me know if there is anything else I can do.


r/swift • • 2d ago

Tutorial iOS 27.1: UIArrangementViewController

Thumbnail
antongubarenko.substack.com
5 Upvotes

r/swift • • 2d ago

News Fatbobman's Swift Weekly #163

Thumbnail
weekly.fatbobman.com
3 Upvotes

r/swift • • 1d ago

A ‘Weak’ Too Far: Debugging a Swift Miscompilation

2 Upvotes

r/swift • • 2d ago

Sysbar: a menu bar system monitor built with SwiftPM only (no .xcodeproj), AppKit + SwiftUI, IOKit/Mach APIs. Open source, plus a few lessons learned

Post image
0 Upvotes

I've been building **Sysbar**, a small macOS menu bar system monitor (CPU with E/P-core split, GPU, memory, disk, network, top processes). It's open source under Apache-2.0, and I thought the implementation might interest people here.

**Repo:** https://github.com/rodrigotrombeta/Sysbar

**Project setup: no Xcode project at all**

- It's a plain SwiftPM `executableTarget` (about 4.3k lines), linking `IOKit` and `ServiceManagement`.

- A ~30-line `build.sh` runs `swift build -c release`, assembles the `.app` bundle by hand (binary, `Info.plist`, icon), ad-hoc signs it with `codesign --sign -` and installs it. You only need the Command Line Tools.

- Release builds are universal: `swift build --arch arm64 --arch x86_64`, then packaged into a DMG.

**Where the data comes from (public APIs only, no sudo, no helper)**

- CPU: `host_processor_info` for per-core ticks, split into E-cores and P-cores on Apple Silicon.

- GPU: `IOServiceMatching("IOAccelerator")`, reading the `PerformanceStatistics` dictionary ("Device Utilization %" and in-use memory).

- Memory: `host_statistics64(HOST_VM_INFO64)`.

- Disk I/O: the `IOBlockStorageDriver` statistics.

- Top processes: `proc_listallpids` + `proc_pid_rusage(RUSAGE_INFO_V4)`.

- Launch at login: `SMAppService.mainApp`.

**UI**

- An `NSStatusItem` with an icon drawn into an `NSImage(size:flipped:drawingHandler:)` on every tick.

- The panels are SwiftUI hosted in an `NSPanel` subclass. A small `NSHostingView` subclass overrides `acceptsFirstMouse` so buttons respond to the first click even when the panel isn't key.

**One lesson that surprised me**

My sparklines started out as SwiftUI `Canvas`. In a panel that stays pinned open and redraws every second, `Canvas` re-rendered through GPU-backed buffers and added **tens of MB** of memory. Switching to plain `Shape` paths (`SparklineShape` filled with a gradient) brought the app back to about **25 MB of RAM**. If you're building something that redraws constantly, measure `Canvas` before committing to it.

**Credits:** the monitoring logic started from the System Stats panel in [oMLX](https://github.com/jundot/omlx), and the menu bar icon is inspired by [Stats](https://github.com/exelban/stats).

I'd appreciate a code review from people who know AppKit better than I do, especially on the `NSPanel`/SwiftUI hosting and hover-tracking parts. Issues and PRs are welcome.


r/swift • • 3d ago

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

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

Anyone using Claude Code with Swift 6.2 lately?

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

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

28 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 • • 5d 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 • • 4d 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 • • 5d 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 • • 6d 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.

9 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 • • 5d 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 • • 5d 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 • • 7d 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.