Loading...
Loading...
Swift 6 and SwiftUI code rules for macOS apps, including concurrency, state, SwiftData, AppKit bridges, and fixes for common compiler errors. Use when writing, reviewing, or debugging Swift code in a Mac app, or on concurrency, Sendable, or "not in scope" errors.
npx skill4agent add daveebbelaar/bama swift-swiftuimac-design| Work | Put it in |
|---|---|
| UI state, views, view models | Default (main actor) |
| CPU-heavy pure work (parsing, image work, diffing) | A |
| Shared mutable state used off the main thread | An |
| A C callback (event tap, Carbon hotkey, CoreAudio listener) | A |
SendableSendablefinal classletMainActor.assumeIsolated { }TimerTask { }Task.detached@unchecked Sendablenonisolated(unsafe)@MainActor@SendableDispatchSource.setEventHandlerDispatchWorkItemaddPeriodicTimeObserver{ @Sendable in ... }@Observable@State@Bindable.environment(model)@ObservationIgnored@State@AppStorageForEach(items)ForEach($items)@Model.modelContainer@Query@Environment(\.modelContext)~/Library/Application Support/<AppName>/APP_STOREuid: UUIDpersistentModelIDCommands@Observable.disabled(...)@FocusedValue.focusedSceneValue@ObservedObjectObservableObjectApp@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) }
}
}.disabled(selectedIDs.isEmpty)test-mac-app.onDeleteCommand.onKeyPressTaskViewColorImageTextSectionLabelMenuGroupSettingsTaskTask { }TodoTaskItemNoteSectionNSPanel.nonactivatingPanelNSHostingViewsizingOptions = []NSViewRepresentableNSTextViewNSStatusItemNSEvent.addLocalMonitorForEventsos-integrations| Error | Fix |
|---|---|
| |
| Make the caller main-actor, or |
| Make the type |
| Split the view into smaller subviews or |
| A type in your code is named |
| Error | Fix |
|---|---|
Static | |
| Copy the Sendable parts (an id, a pid) out of the notification before |
| Observer token captured before it is assigned | Keep the token in a small |
| "pattern that the region-based isolation checker does not understand" in a task group | Use an array of |
Vars changed from | |
| |