Snippets
SwiftUI disabled, redacted, and allowsHitTesting
Represent unavailable, loading, private, and pass-through states with the right interaction and visual modifiers.
4 min readUpdated 2026-06
import SwiftUI
struct LoadingProfileCard: View {
let isLoading: Bool
let canSave: Bool
var body: some View {
VStack(alignment: .leading, spacing: 12) {
Text("Taylor Chen").font(.headline)
Text("iOS Engineer").foregroundStyle(.secondary)
Button("Save") {}
.disabled(!canSave || isLoading)
}
.padding()
.redacted(reason: isLoading ? .placeholder : [])
}
}Implementation notes
disabled is inherited by descendants, which is useful for forms but surprising on large containers.
redacted is visual; pair it with disabled when controls should not be used during loading.
allowsHitTesting(false) lets events pass through a view, which is useful for decorative overlays.
Checklist
Do not rely on disabled appearance alone; explain blocked actions when needed.
Use unredacted for labels or controls that must remain visible.
Verify skeleton layouts match the final content footprint.
Related reference
SwiftUI Alerts and Confirmation Dialogs
Use alerts for urgent decisions and confirmationDialog for action choices that can adapt across iPhone, iPad, and macOS.
SwiftUI Tap, Long Press, and Drag Gestures
Pick the simplest gesture that matches the user's intent, then promote to explicit Gesture values only when you need state or composition.
SwiftUI clipShape, mask, and contentShape
Clipping controls what is visible, masking controls alpha, and contentShape controls where interaction happens.