Command Palette

Search for a command to run...

UnylyUnyly
Назад к скиллам

swiftui-ui-patterns

БесплатноБез исполняемых скриптовНе проверен

Builds SwiftUI screens and app structure from a small set of proven patterns: who owns each piece of state, a tab-and-navigation-stack app shell, enum-driven…

TerminalSkillsот TerminalSkills★ 221 звезда на GitHub

Об этом скилле

SwiftUI UI Patterns

Overview

Most SwiftUI screens are assembled from the same few decisions: where each piece of state lives, how the user moves between screens, how modal presentations are triggered, and what the view shows while data is loading, missing or broken. Getting these right once makes the rest of the view code short. This skill gives one pattern for each decision, with the API availability checked against Apple's documentation, and two complete examples to copy the shape from. It deliberately leaves out component catalogues: for a single control, read its documentation page.

Instructions

1. Look before writing

  • Deployment target decides which column of the tables below applies. Find it in the project settings or Package.swift (platforms:).
  • House style. Search for the nearest existing screen and match it: grep -rnE "NavigationStack|NavigationSplitView|TabView|\.sheet\(" --include="*.swift" . Do not introduce a second navigation or state style into a project that already has one.
  • Xcode version. With Xcode 27 or later @State is a macro that creates a class-typed initial value once. With Xcode 26 or earlier it is a property wrapper, and the initial-value expression runs every time the view is initialised (only the first result is kept). On older Xcode, keep model initialisers cheap or create the model in .task.

2. Decide who owns each piece of state

Pick the owner first, then the declaration follows.

The data is Owner writes A child that receives it writes Before iOS 17
A value used by one view (toggle, text, selection) @State private var @Binding var if it edits, let if it reads same
A reference model created by this view @State private var model = CartModel() on an @Observable class let model: CartModel to read; @Bindable var model when it needs $model.field @StateObject / @ObservedObject on an ObservableObject
A service shared by many screens .environment(client) near the root @Environment(LibraryClient.self) private var client .environmentObject / @EnvironmentObject
A system value (dismiss, locale, color scheme) provided by SwiftUI @Environment(\.dismiss) private var dismiss same

Rules: state is private and lives in the highest view that needs it, no higher. Pass leaf views the values they display, not the whole model. Reading a type from the environment that nobody injected throws at run time; declare it optional (private var client: LibraryClient?) when it may be absent. Plain values in @State are enough for most screens; add a model class when logic must be shared or tested.

3. App shell: tabs, each with its own stack

One TabView; each tab owns a NavigationStack and its own path, so switching tabs keeps each history.

  • iOS 18+: Tab("Library", systemImage: "books.vertical", value: AppTab.library) { … } inside TabView(selection:). A search tab is Tab(value: AppTab.search, role: .search) { … }. Add .tabViewStyle(.sidebarAdaptable) to get a sidebar on iPad.
  • iOS 16–17: the same structure with .tabItem { Label(…) }.tag(…) on each child. tabItem is deprecated in the 27.2 SDKs, so isolate it behind an availability check.
  • iPad or Mac apps organised around a sidebar and detail use NavigationSplitView in place of tabs.
  • NavigationView is deprecated; do not write new code with it.

4. Navigation: values, not views

Describe destinations as data. Declare a Hashable route enum per stack, bind the stack to an array of routes, and map routes to views in one place.

enum LibraryRoute: Hashable {
    case shelf(Shelf.ID)
    case book(Book.ID)
}
  • Push from a row with NavigationLink(book.title, value: LibraryRoute.book(book.id)), or from code with path.append(.book(id)).
  • Pop to root with path.removeAll(); a deep link is path = [.shelf(2), .book(4821)].
  • Put navigationDestination(for:) on the stack's root content. Apple's documentation warns against placing it inside lazy containers such as List or LazyVStack, where the stack may not see it.
  • Use NavigationPath only when one stack must hold unrelated route types; a typed array is easier to inspect and restore.
  • Store identifiers in routes, not whole models, so a path can be rebuilt from a URL.

5. Presentations: one optional enum per presenter

Several Boolean flags for mutually exclusive sheets allow impossible states. Use one optional Identifiable enum and sheet(item:):

enum LibrarySheet: Identifiable {
    case addBook
    case editShelf(Shelf.ID)
    var id: String {
        switch self {
        case .addBook: "addBook"
        case .editShelf(let id): "editShelf-\(id)"
        }
    }
}
  • The presenter sets sheet = .editShelf(shelf.id); setting nil dismisses. If the item changes while shown, SwiftUI replaces the sheet.
  • Inside the sheet, close with @Environment(\.dismiss). Wrap sheet content in its
Полный SKILL.md на GitHub

Установить swiftui-ui-patterns в Claude Code и Claude Desktop

Зарегайся, чтобы установить скилл

Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.

  • Открой команду установки в одну строку
  • Сохраняй скиллы в синхронизируемую библиотеку
  • Уведомления, когда скиллы обновляются
Зарегаться бесплатноУ меня уже есть аккаунт

Разрешённые инструменты

Инструменты, которые скиллу разрешено вызывать.

Без ограничений — скилл может использовать любой инструмент.

Вложенные файлы

_scores.json

FAQ

Что делает скилл swiftui-ui-patterns?

Builds SwiftUI screens and app structure from a small set of proven patterns: who owns each piece of state, a tab-and-navigation-stack app shell, enum-driven routes and sheets, async loading with explicit phases, searchable lists, form sheets and previews for every state. States the minimum OS for each API and gives the fallback for older targets. Use when the user says "build this screen in SwiftUI", "set up navigation for my app", "TabView with NavigationStack", "how should I pass this model down", "show a sheet from a list row", "handle loading and error states", "add deep links", or starts a new SwiftUI app.

Как установить скилл swiftui-ui-patterns?

Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.

Скилл swiftui-ui-patterns запускает скрипты?

Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.

Похожие скиллы

Сравнить swiftui-ui-patterns с