Installs into .claude/skills of the current project.
Sponsors
SSkills DirectorySkills Directory
Know which skills are safe — weekly.
SSkills DirectorySkills Directory
Is that skill safe to install?
Are you the author of Swiftui Knowledge Patch?
Add the live security badge to your README. It updates with every re-scan.
[](https://www.skillsdirectory.com/skills/nevaberry-swiftui-knowledge-patch)
---
name: swiftui-knowledge-patch
description: SwiftUI
version: "iOS 27 beta 4 / Xcode 27 beta 4"
license: MIT
metadata:
author: Nevaberry
---
# SwiftUI Knowledge Patch
Use this skill when implementing or migrating SwiftUI state, builders, documents,
navigation, window adaptation, gestures, spatial interfaces, or framework integration.
Read the relevant reference for complete guidance and examples.
## Reference index
| Reference | Topics |
| --- | --- |
| [Documents, Web Content, Images, and Text](references/documents-web-and-text.md) | Document scenes, snapshot and URL I/O, file-wrapper adapters, export, WebPage, WebView, AsyncImage, text editing, search tokens |
| [Interaction, Spatial Layout, and Charts](references/interaction-spatial-and-charts.md) | Multi-item drags, reordering, swipe actions, gesture inputs and velocity, hover, spatial layout, RealityKit, immersive effects, Chart3D |
| [Scenes, Interoperability, and Diagnostics](references/scenes-interoperability-and-diagnostics.md) | Assistive Access, remote immersive rendering, utility panels, UIKit and AppKit hosting, traits, widgets, accessibility, skill export |
| [State, Concurrency, Animation, and Builders](references/state-concurrency-and-builders.md) | State initialization, callback concurrency, ContentBuilder, concrete types, MapKit and Charts compatibility, synthesized animation data |
| [Visual Design, Navigation, and Windows](references/visual-navigation-and-windows.md) | Window resizing, toolbars, menus, tabs, search placement, dialogs, glass, colors, arrangements, hardware regions, hinge state |
## Deprecations and migration
### Full-screen assumptions and window sizes
Migrate away from the deprecated `UIRequiresFullscreen` Info.plist key and let
`NavigationSplitView` adapt its visible columns as the window resizes.
The scene's existing `.commands { TextEditingCommands() }` also populates the
iPadOS 26 menu bar.
iPhone apps can be resized in iPhone Mirroring and when running on iPad.
Use the resize handles in Xcode 27 Live Previews to test those window sizes.
### State initialization and composition
The Xcode 27 `@State` macro lazily evaluates the initial value once per view
identity, including on iOS 17, macOS 14, and aligned releases.
For values supplied by `init`, omit the inline default because it takes precedence,
and initialize non-state stored properties before assigning state.
Remove other property wrappers stacked with `@State`. If an extension used a
synthesized memberwise initializer for a view with private state, define the
initializer explicitly.
```swift
struct Counter: View {
let title: String
@State private var count: Int
init(title: String, start: Int) {
self.title = title
self.count = start
}
var body: some View { Text("\(title): \(count)") }
}
```
### Builder compatibility
Xcode 27 unifies builders such as `ViewBuilder` under `@ContentBuilder`, which
works with older deployment targets. Builders including those on `Group`,
`ForEach`, and `Section` accept unconstrained elements, with the assembled content
conforming to the required protocol when its elements do.
A two-expression stack can now produce `VStack<TupleContent<Text, Text>>`, so
prefer opaque return types such as `some View`. For a concrete constraint
back-deploying below iOS 27, iPadOS 27, macOS 27, or visionOS 27, retain
`VStack<TupleView<(Text, Text)>>` and explicitly construct
`VStack { TupleView((Text("A"), Text("B"))) }`.
When a styled expression becomes ambiguous in `background` or `overlay`, use the
closure overload, such as `.overlay { Color.blue.opacity(0.3).blendMode(.overlay) }`.
Qualify colliding names in builder bodies, such as `SwiftUI.Color.clear`.
If an empty nested builder resolves to `EmptyMapContent` when MapKit is in scope,
give it an explicit `EmptyContent()` or `EmptyView()`, as in `Group { EmptyView() }`.
For a conditionally compiled branch that can disappear, put the empty value in
`#else`.
When a `Chart` closure with roughly ten or more branches times out while
back-deploying below iOS 27, iPadOS 27, macOS 27, or visionOS 27, move the branches
to an `@ChartContentBuilder` function returning `some ChartContent` and call that
function from the chart closure.
### Off-main callbacks
SwiftUI can call `Layout` requirements, `Shape.path(in:)`, `visualEffect`, and the
transform closure of `onGeometryChange` off the main actor. Capture a sendable
snapshot of view state before a `@Sendable` callback runs, for example
`Text("Loading").visualEffect { [pulse] content, _ in content.blur(radius: pulse ? 2 : 0) }`.
## Navigation, toolbars, and windows
### Toolbar grouping and overflow
Place `ToolbarSpacer(.fixed, placement: .primaryAction)` between items in the
same toolbar placement to put them in separate Liquid Glass groups.
Use `.visibilityPriority(.high)` on a `ToolbarItemGroup` to keep it visible longer
as space shrinks. Use `ToolbarOverflowMenu` for actions that should always live in
overflow, and `.topBarPinnedTrailing` for an action that must stay visible.
Apply `.toolbarMinimizeBehavior(.onScrollDown, for: .navigationBar)` to a scroll
view to collapse the navigation bar as the user scrolls down.
### Vertical toolbar controls
Read `@Environment(\.toolbarVerticalEdge)` to position custom UI relative to the
system's vertical controls, or use `toolbarVerticalBehavior(_:)` to opt a view out
and move its bar content to the standard top and bottom toolbars.
Set individual standard or customizable items with `axisBehavior(_:)` and values
such as `.horizontalOnly` or `.verticalPreferred`. Use
`toolbarVerticalCompressionBehavior(_:)` with `.prefersToolbarItems` or
`.prefersTabBar` to choose which content to favor when bars share limited space.
### Tabs and search placement
Declare `Tab(role: .prominent) { CartView() }` inside a `TabView` to place a
destination at the bottom trailing edge, apart from the other tabs.
Apply `.searchable(text:)` to the outer `NavigationSplitView`. In iOS and iPadOS 26,
this places search at the bottom on iPhone and in the top trailing corner on iPad.
### Window activity and menu icons
Standard icons and text dim when an iPad window becomes inactive. Read
`@Environment(\.appearsActive)` in custom controls and use its value to adjust
their appearance. iPad and Mac menu bars now show fewer command icons by default;
apply `.labelStyle(.titleAndIcon)` to the command's `Label` to show its icon.
## Documents, images, and presentations
### Document architecture and creation
Place `DocumentGroup` before `WindowGroup` in `App.body` when the app declares
both. This opts the app into SwiftUI's document-based architecture.
Give each launch-scene `NewDocumentButton` a `DocumentCreationSource` with its
own ID. SwiftUI passes the selected source through the `DocumentGroup` creation
context so the initializer can start the corresponding flow.
### Snapshot-based document I/O
Use an `@Observable` model in `DocumentGroup` and conform it to `WritableDocument`
to declare supported formats, supply
`@MainActor func snapshot(contentType: UTType) async throws -> sending Snapshot`,
and select a `DocumentWriter` using `configuration.contentType` in
`writer(configuration:)`. The writer gets a destination URL, an optional previous
snapshot for incremental writes, and Foundation `Subprogress` for reporting progress.
For reading, `ReadableDocument` declares its supported formats and applies the
snapshot returned by a `DocumentReader`.
### Image caching
On the 2027 OS releases, `AsyncImage` caches according to HTTP response headers
by default. Use
`AsyncImage(request: URLRequest(url: imageURL, cachePolicy: .returnCacheDataElseLoad))`
for per-request control, or set a shared session configured with a custom
`URLCache` on an ancestor using `.asyncImageURLSession(imageSession)`.
### Item-bound dialogs and alerts
Set an optional state item to a value to present
`.confirmationDialog("Delete?", item: $pendingItem) { item in DeleteButton(item) }`.
The `.alert` overload takes the same `item:` binding and passes the item to its
actions closure. Present an alert directly from an optional error with
`alert(error:actions:)` or `alert(error:actions:message:)`; SwiftUI uses the error
to supply the title and passes it to the content closures.
## Interaction and adaptive layout
### Dragging, reordering, and swipe actions
For multi-item drags, mark each draggable child with its ID, then supply the
selection and a resolver on the container. SwiftUI asks for the payloads lazily
at the drop. On macOS, you can opt into deletion and remove the reported IDs when
the session ends with `.delete`.
Mark the `ForEach` with `.reorderable()` and update the underlying collection from
the `ReorderDifference` delivered to `.reorderContainer(for:)`. The same pattern
works on watchOS, with single-collection moves placing the source IDs before the
destination ID or at the end.
Attach `.swipeActions { DeleteButton() }` to each row in a custom layout and apply
`.swipeActionsContainer()` to its enclosing `ScrollView` to coordinate the rows'
swipe actions.
### Adaptive arrangements and hardware regions
Use `ArrangementView` to lay out primary and secondary content in response to the
environment. Select a style with `arrangementViewStyle(_:)`, or implement
`ArrangementViewStyle.makeBody(configuration:)` and build a custom layout from
`configuration.primary` and `configuration.secondary`.
Query a view's intersecting hardware regions with
`GeometryProxy.reservedRegions(kind:options:layoutDirectionBehavior:)` to work
around camera occlusions or hinge divisions using kinds such as `.occlusion`
and `.division`. Pass `.includeInactive` to include inactive regions and use
`ReservedRegion.ID` to track the same region across coordinate spaces or over time.