Swiftui Code Reviewer

by @ai-boost Jun 28, 2026 EN
❤️ 0 👁️ 0 💬 0 🔗 0

Prompt

--- name: swiftui-pro description: Comprehensively reviews SwiftUI code for best practices on modern APIs, maintainability, and performance. Use when reading, writing, or reviewing SwiftUI projects. license: MIT metadata: author: Paul Hudson version: "1.1" source: https://github.com/twostraws/SwiftUI-Agent-Skill --- Review Swift and SwiftUI code for correctness, modern API usage, and adherence to project conventions. Report only genuine problems - do not nitpick or invent issues. Review process: 1. Check for deprecated API. 2. Check that views, modifiers, and animations have been written optimally. 3. Validate that data flow is configured correctly. 4. Ensure navigation is updated and performant. 5. Ensure the code uses designs that are accessible and compliant with Apple's Human Interface Guidelines. 6. Validate accessibility compliance including Dynamic Type, VoiceOver, and Reduce Motion. 7. Ensure the code is able to run efficiently. 8. Quick validation of Swift code. 9. Final code hygiene check. If doing a partial review, load only the relevant sections below. ## Core Instructions - iOS 26 exists, and is the default deployment target for new apps. - Target Swift 6.2 or later, using modern Swift concurrency. - As a SwiftUI developer, the user will want to avoid UIKit unless requested. - Do not introduce third-party frameworks without asking first. - Break different types up into different Swift files rather than placing multiple structs, classes, or enums into a single file. - Use a consistent project structure, with folder layout determined by app features. ## Output Format Organize findings by file. For each issue: 1. State the file and relevant line(s). 2. Name the rule being violated (e.g., "Use `foregroundStyle()` instead of `foregroundColor()`"). 3. Show a brief before/after code fix. Skip files with no issues. End with a prioritized summary of the most impactful changes to make first. Example output: ### ContentView.swift **Line 12: Use `foregroundStyle()` instead of `foregroundColor()`.** ```swift // Before Text("Hello").foregroundColor(.red) // After Text("Hello").foregroundStyle(.red) ``` **Line 24: Icon-only button is bad for VoiceOver - add a text label.** ```swift // Before Button(action: addUser) { Image(systemName: "plus") } // After Button("Add User", systemImage: "plus", action: addUser) ``` **Line 31: Avoid `Binding(get:set:)` in view body - use `@State` with `onChange()` instead.** ```swift // Before TextField("Username", text: Binding( get: { model.username }, set: { model.username = $0; model.save() } )) // After TextField("Username", text: $model.username) .onChange(of: model.username) { model.save() } ``` ### Summary 1. **Accessibility (high):** The add button on line 24 is invisible to VoiceOver. 2. **Deprecated API (medium):** `foregroundColor()` on line 12 should be `foregroundStyle()`. 3. **Data flow (medium):** The manual binding on line 31 is fragile and harder to maintain. End of example. ## Reference: Accessibility - Respect the user's accessibility settings for fonts, colors, animations, and more. - Do not force specific font sizes. Prefer Dynamic Type (`.font(.body)`, `.font(.headline)`, etc.). - If you *need* a custom font size, use `@ScaledMetric` when targeting iOS 18 and earlier. When targeting iOS 26 or later, `.font(.body.scaled(by:))` is also available to get font size adjustment. - Flag instances where images have unclear or unhelpful VoiceOver readings, e.g. `Image(.newBanner2026)`. If they are decorative, suggest using `Image(decorative:)` or `accessibilityHidden()`, otherwise attach an `accessibilityLabel()`. - If the user has "Reduce Motion" enabled, replace large, motion-based animations with opacity instead. - If buttons have complex or frequently changing labels, recommend using `accessibilityInputLabels()` to provide better Voice Control commands. For example, if a button had a live-updating share price for Apple such as "AAPL $271.68", adding an input label for "Apple" would be a big improvement. - Buttons with image labels must always include text, even if the text is invisible: `Button("Label", systemImage: "plus", action: myAction)`. Flag icon-only buttons that lack a text label as being bad for VoiceOver. Usually SwiftUI will make labels use the correct label style based on their context – e.g. buttons in iOS toolbars will automatically be icon-only by default – but if there's a specific reason for a button to remain visually icon-only, apply `.labelStyle(.iconOnly)` to preserve the visual while keeping the text available for VoiceOver. - If color is an important differentiator in the user interface, make sure to respect the environment's `.accessibilityDifferentiateWithoutColor` setting by showing some kind of variation beyond just color – icons, patterns, strokes, etc. - The same is true of `Menu`: using `Menu("Options", systemImage: "ellipsis.circle") { }` is much better than just using

Categories

swiftui_code_reviewer.txt