Logo: Swift Swiftui

Swift Swiftui

Communautéit
daveebbelaar
swift-swiftui

Swift 6- a SwiftUI-Code-Reegelen fir macOS-Apps, dorënner Concurrency, State, SwiftData, AppKit-Brécken a Léisunge fir heefeg Compiler-Feeler. Benotzt dëst, wann Dir Swift-Code an enger Mac-App schreift, iwwerpréift oder debuggt, oder wann et ëm Concurrency-, Sendable- oder „not in scope“-Feeler geet.

Add to TypingMind

Iwwersiicht

Editeurdaveebbelaar
Repositorybama
Skill-Nummswift-swiftui
Stären
952
Forks
136
Matgeliwwert Dateien
1
LizenzMIT
Linken
  • Instruktiounen am Markdown-Format

    Eng SKILL.md-Datei, déi de Modell bei Bedarf luet, soudatt nëmmen Token ufalen, wann eng Ufro tatsächlech dozou passt.

  • Funktionéiert mat all LLM

    KI-Skills si reng Markdown, keen ubidderspezifesche Code. Dofir funktionéiert dëse Skill mat GPT, Claude, Gemini, Grok oder engem lokale Modell.

  • 1 matgeliwwert Dateien

    Skripten, Virlagen a Referenzen, déi de Modell beim Schaffe liese kann. D'Dateie kënnen nëmme gelies ginn a ginn ni ausgeféiert.

  • Open Source

    daveebbelaar huet de Skill op GitHub verëffentlecht. Liest de Quelltext, ier Dir de Skill installéiert.

Installatioun

Installéiert de KI-Skill Swift Swiftui an TypingMind, fir e mat all LLM ze benotzen, oder setzt en an en anere KI-Agent an, deen SKILL.md liest.

1

An TypingMind installéieren

TypingMind installéiert e Skill direkt aus sengem GitHub-Dossier — dobäi gëtt SKILL.md gelies, d'Ressourcedateie gi gebëndelt an d'Resultat gëtt lokal gespäichert.

  1. Maacht d'App op a gitt op Plugins → Skills.
  2. Wielt „Vu GitHub installéieren“.
  3. Pecht d'URL vum Skill-Dossier, déi hei drënner steet, an a bestätegt d'Installatioun.
    https://github.com/daveebbelaar/bama/tree/main/skills/code/swift-swiftui
  4. Aktivéiert de Skill an all Chat, an deem Dir e benotze wëllt.
Plugins → Skills → Skill derbäisetzen → Iwwer eng GitHub-URL. Pecht dann d'URL vum Dossier an a klickt op Weider.
2

An engem anere KI-Agent installéieren

All KI-Agent, deen d'Format Agent Skills liest, kann dëse Skill benotzen — kopéiert den Dossier an d'Skill-Verzeechnes vun deem KI-Agent.

Claude Code — .claude/skills
git clone --depth 1 https://github.com/daveebbelaar/bama.git /tmp/bama
mkdir -p .claude/skills
cp -r /tmp/bama/skills/code/swift-swiftui .claude/skills/swift-swiftui
Start Claude Code nom Kopéieren nei, fir datt den neie Skill erkannt gëtt.

An TypingMind benotzen

Aktivéiert Swift Swiftui an engem Chat vun TypingMind, an de Modell iwwerhëlt de Rescht. Den Numm an d'Beschreiwung stinn am System-Prompt. Soubal eng Ufro dozou passt, luet de Modell déi komplett Instruktioune selwer — Dir musst de Skill ni manuell opruffen, an et fale keng Token un, bis en tatsächlech benotzt gëtt.

De Modell luet Swift Swiftui automatesch, soubal eng Ufro dozou passt.

Funktionéiert mat all KI-Modell

KI-Skills si reng Markdown-Instruktiounen amplaz vun ubidderspezifeschem Code. Dofir ass Swift Swiftui net un de Modell gebonnen, fir deen de Skill geschriwwe gouf. Installéiert en eemol an TypingMind a benotzt e mat GPT-5, Claude, Gemini, Grok, DeepSeek, Mistral, Llama oder engem lokale Modell, deen Dir selwer bedreift — alles mat Ären eegenen API-Schlësselen.

  • Gëtt nëmme gelueden, wann et néideg ass

    De System-Prompt enthält nëmmen den Numm an d'Beschreiwung. D'Instruktioune gi bei der éischter passender Ufro gelueden, soudatt en onbenotzte Skill näischt kascht.

  • De Modell am lafende Chat wiesselen

    Well de Skill aus Instruktiounen amplaz vu Code besteet, funktionéiert en och no engem Modellwiessel — den nächste Modell liest déi selwecht SKILL.md-Datei.

Skill-Instruktiounen

Dëst ass den Inhalt vu SKILL.md, deen de Modell luet. Liest e virun der Installatioun — e Skill besteet aus Instruktiounen, déi Äre Modell befollegt.

Swift and SwiftUI

The code is right when it compiles with zero warnings in Swift 6 language mode and the app does what the story says. For how it should look, call the Skill tool with mac-design. For copyable view code, read ../../design/mac-design/patterns.md.

Concurrency

The template sets main-actor default isolation: every type and function runs on the main actor unless you say otherwise. UI code needs no annotations.

WorkPut it in
UI state, views, view modelsDefault (main actor)
CPU-heavy pure work (parsing, image work, diffing)A nonisolated function marked @concurrent
Shared mutable state used off the main threadAn actor
A C callback (event tap, Carbon hotkey, CoreAudio listener)A nonisolated static func that hops back with Task { @MainActor in ... }
  • Data that crosses actors is Sendable: structs and enums of Sendable values, or final class with only let properties.
  • MainActor.assumeIsolated { } inside a callback you know runs on the main thread (a main run loop Timer, a main queue notification).
  • Task { } inherits the actor. Task.detached only when it must not.
  • Fix a concurrency error at its type, not with @unchecked Sendable or nonisolated(unsafe). Those two are a last resort, with a comment why.
  • Runtime trap the compiler misses. A closure created inside a @MainActor type and passed to an API without a @Sendable closure parameter (DispatchSource.setEventHandler, DispatchWorkItem, addPeriodicTimeObserver, CoreAudio listener blocks) inherits the main actor. When it runs on a background queue, Swift 6 crashes the app. Write it as { @Sendable in ... }, and run every background path once after any concurrency change.

State

  • @Observable classes for models. @State in the view that owns one, @Bindable to bind to its properties, .environment(model) to share it.
  • @ObservationIgnored on caches, timers, and handles, so they never trigger a redraw.
  • @State for view-local values. @AppStorage for small preferences. Keychain for secrets.
  • ForEach(items) over values, never ForEach($items) for data the user can delete: a row can read an index that no longer exists and crash. Get a binding by looking the item up by id.

SwiftData

  • @Model classes, .modelContainer on the scene, @Query in views, @Environment(\.modelContext) to insert and delete.
  • Every new property has a default value, so existing stores still open.
  • Store at ~/Library/Application Support/<AppName>/. Allow an override (APP_STORE) so tests never touch the real data.
  • Give every model its own uid: UUID. persistentModelID changes on the first save, so it breaks selection and lookups.
  • Undo: register the reverse of each action on the window's undo manager. SwiftData's automatic undo is not reliable. Code in ../../design/mac-design/patterns.md (Undo with SwiftData).
  • Need SQL, a CLI, or several processes on one file? Use SQLite with WAL through a small library target instead.

Menu commands

SwiftUI Commands do not observe @Observable models, so a title or a .disabled(...) that reads the model goes stale. In testing, neither @FocusedValue (from .focusedSceneValue) nor an @ObservedObject inside the commands updated reliably: the menu stayed disabled with a row selected. What works: mirror the selection into a small ObservableObject, observe it in the App, and pass the values into the commands. The App's body then rebuilds the menus when they change.

swift
@MainActor final class MenuState: ObservableObject {
    static let shared = MenuState()
    @Published private(set) var selection: Set<UUID> = []
    func update(_ s: Set<UUID>) { if selection != s { selection = s } }
}
// AppModel: var selection: Set<UUID> = [] { didSet { MenuState.shared.update(selection) } }

struct MyApp: App {
    @ObservedObject private var menu = MenuState.shared
    var body: some Scene {
        Window("App", id: "main") { ContentView() }
            .commands { AppCommands(model: model, selectedIDs: menu.selection) }
    }
}

Disable items with .disabled(selectedIDs.isEmpty) and resolve the target again when the item fires. Never ship items that stay enabled and do nothing. Check the menu from outside the app (test-mac-app skill, "Menu check").

A menu shortcut also fires while a text field has focus. Never use Delete, Command-Delete, arrows, or Return as menu shortcuts. Handle them on the list with .onDeleteCommand and .onKeyPress.

Names Swift already uses

Never name a type Task, View, Color, Image, Text, Section, Label, Menu, Group, or Settings. Task breaks every Task { }. Use Todo, TaskItem, NoteSection.

AppKit bridges

SwiftUI covers windows, lists, and forms. AppKit is still the answer for:

  • Floating panels that do not steal focus: NSPanel with .nonactivatingPanel hosting a SwiftUI view (NSHostingView, with sizingOptions = [] for a fixed frame).
  • Text views with custom behavior: NSViewRepresentable around NSTextView.
  • Status items with custom click handling: NSStatusItem.
  • Key and mouse monitors: NSEvent.addLocalMonitorForEvents. Remove the monitor when the view goes away.

For system hooks (hotkeys, Accessibility, screen capture), call the Skill tool with os-integrations.

Compiler errors

ErrorFix
cannot find 'X' in scope right after adding a fileswift package clean --scratch-path ~/Library/Developer/<AppName>/build
Main actor-isolated ... from a nonisolated contextMake the caller main-actor, or await the call
Sending 'x' risks causing data racesMake the type Sendable, or keep it on one actor
The compiler is unable to type-check this expressionSplit the view into smaller subviews or let constants
ambiguous use of 'Task'A type in your code is named Task; rename it

Fix the first error first. Later errors often come from it.

Swift 6 errors

Moving an existing Swift 5 app? Read ../../ship/build-and-verify/existing-app.md first: expect several build rounds, then hunt the runtime trap above.

ErrorFix
Static let of a non-Sendable type (formatter, NSFont, CFString)@MainActor on the enclosing type, a computed var, or a commented nonisolated(unsafe)
sending 'note' risks causing data races in a main-queue observerCopy the Sendable parts (an id, a pid) out of the notification before MainActor.assumeIsolated
Observer token captured before it is assignedKeep the token in a small @MainActor class
"pattern that the region-based isolation checker does not understand" in a task groupUse an array of Task { @MainActor in ... } and await each one
Vars changed from OperationQueue blocks under NSLockOSAllocatedUnfairLock(initialState:)
@objc action on an NSMenuItem subclass@MainActor @objc func

Done when the app builds with zero warnings in Swift 6 language mode and the story's acceptance checks pass.

Matgeliwwert Dateien

De Modell liest dës Dateie bei Bedarf, wärend de Skill gelueden ass. Si ginn als liesbar Dateie bereetgestallt a ginn ni ausgeféiert.

Heefeg gestallte Froen

Wat mécht de KI-Skill Swift Swiftui?

Swift 6- a SwiftUI-Code-Reegelen fir macOS-Apps, dorënner Concurrency, State, SwiftData, AppKit-Brécken a Léisunge fir heefeg Compiler-Feeler. Benotzt dëst, wann Dir Swift-Code an enger Mac-App schreift, iwwerpréift oder debuggt, oder wann et ëm Concurrency-, Sendable- oder „not in scope“-Feeler geet.

Firwat Swift Swiftui op TypingMind benotzen?

Well Dir en eemol installéiert a mat all Modell benotze kënnt. Swift Swiftui besteet aus einfachem Markdown amplaz vun ubidderspezifeschem Code. Dee selwechte Skill funktionéiert also mat GPT-5, Claude, Gemini, Grok oder engem lokale Modell – an Dir kënnt de Modell matzen am Chat wiesselen, ouni datt de Skill ophält ze funktionéieren. TypingMind benotzt Är eegen API-Schlësselen, sou datt Dir d'Ubidder direkt bezuelt, amplaz en Abonnement pro Benotzerplaz ze bezuelen. Är Skills a Chats bleiwen an Ärem eegene Späicher.

Wéi installéieren ech Swift Swiftui an TypingMind?

Maacht an TypingMind Plugins → Skills → Vu GitHub installéieren op a setzt https://github.com/daveebbelaar/bama/tree/main/skills/code/swift-swiftui an. TypingMind liest d'Datei SKILL.md, bëndelt déi zougehéiereg Dateien an installéiert dat Ganzt als Skill, deen Dir pro Chat aktivéiere kënnt.

Wéi eng KI-Modeller kënnen Swift Swiftui benotzen?

All Modell, deen Dir an TypingMind verbënnt. KI-Skills sinn einfach Markdown-Instruktiounen an net ubidderspezifesche Code. Dofir kënne GPT, Claude, Gemini, Grok a lokal Modeller dëse Skill lueden, wann eng Ufro dozou passt.

Wéi vill KI-Modeller kann ech mat Swift Swiftui benotzen?

Esou vill wéi Dir wëllt. Soulaang e Modell Skills ënnerstëtzt, kënnt Dir Swift Swiftui domat benotzen – zum Beispill mat GPT, Claude, Gemini, Grok, DeepSeek, Mistral oder Llama – alles op TypingMind mat Ären eegenen API-Schlësselen.

Ass de KI-Skill Swift Swiftui gratis?

Jo. daveebbelaar huet de Skill ënner der Lizenz MIT op GitHub publizéiert. Dir bezuelt nëmmen Ären eegene KI-Ubidder fir d'Token, déi Dir benotzt.

Wat si KI-Skills?

E KI-Skill ass e weiderverwendbare Pak vun Instruktiounen, deen engem KI-Modell bäibréngt, wéi en eng bestëmmt Aufgab erfëllt. E follegt dem oppenen Agent Skills-Format: eng Datei SKILL.md mat engem Numm an enger Beschreiwung, plus all Scripten, Virlagen oder Referenzdateien, déi de Modell eventuell brauch. De Modell liest d'Instruktiounen eréischt, wann Är Ufro zum Skill passt. En installéierte Skill kascht also näischt, bis e benotzt gëtt.

Wéi ënnerscheede sech KI-Skills vu Plugins oder MCP-Serveren?

E Plugin oder MCP-Server gëtt engem Modell nei Tools, déi en opruffe kann – Code, deen iergendwou leeft an e Resultat zeréckgëtt. E KI-Skill gëtt dem Modell dogéint Wëssen an eng Virgoensweis: wéi en eng Aufgab ugeet, wéi eng Schrëtt e maache soll a wéi eng gutt Ausgab ausgesäit. Skills bestinn aus einfachem Markdown, brauche kee Server, keen API-Schlëssel a kee Lafzäitëmfeld a funktionéiere mat all Modell.

Alleguer weisen

Elo Ären eegene KI-Aarbechtsberäich ariichten

Abonnéiert Iech op eisen Newsletter, fir iwwer nei Funktiounen an zukünfteg Gewënnspiller informéiert ze ginn 👇