From swiftui
Enforces idiomatic Swift practices: native string/URL methods, FormatStyle over C formatting, safe unwrapping, count(where:), Date.now, and more for code gen/review.
npx claudepluginhub fradser/dotclaude --plugin swiftuiswiftui-review/references/# Swift
- Prefer Swift-native string methods over Foundation equivalents: use `replacing("a", with: "b")` not `replacingOccurrences(of: "a", with: "b")`.
- Prefer modern Foundation API: `URL.documentsDirectory` instead of `FileManager` directory lookups, `appending(path:)` to append strings to a URL.
- Never use C-style number formatting like `String(format: "%.2f", value)`. Use `Text(value, format: .number.precision(.fractionLength(2)))` or similar `FormatStyle` APIs.
- Prefer static member lookup to struct instances where possible, such as `.circle` rather than `Circle()`, and `.bordered.../swift-lintFormats and lints Swift code using swift-format on the specified path (or current directory). Launches agent with isolated context, reports summary and modified files count.
/swiftlintRuns SwiftLint to check Swift code style, shows violations by severity, and offers auto-fix for compatible issues. Also supports strict mode.
/auditAnalyzes iOS/Swift projects to suggest relevant audits or runs specified ones (e.g., memory, concurrency, accessibility, SwiftUI performance, security).
Share bugs, ideas, or general feedback.
replacing("a", with: "b") not replacingOccurrences(of: "a", with: "b").URL.documentsDirectory instead of FileManager directory lookups, appending(path:) to append strings to a URL.String(format: "%.2f", value). Use Text(value, format: .number.precision(.fractionLength(2))) or similar FormatStyle APIs..circle rather than Circle(), and .borderedProminent rather than BorderedProminentButtonStyle().!) and force try unless the failure is truly unrecoverable, and even then prefer using fatalError() with a clear description. If possible, use if let, guard let, nil-coalescing, or try?/do-catch.localizedStandardContains() as opposed to contains() or localizedCaseInsensitiveContains().Double over CGFloat, except when using optionals or inout; Swift is able to bridge the two freely except in those two cases.count(where:) rather than filter() followed by count.Date.now over Date() for clarity.import SwiftUI is already in a file, you do not need to add import UIKit or import AppKit to access things like UIImage or NSImage – they are imported automatically on the appropriate platform.PersonNameComponents with modern formatting over simple string interpolation such as Text("\(firstName) \(lastName)").books.sorted { $0.author < $1.author }, prefer to make the type in question conform to Comparable so the sort order is centralized.Date initializer API such as Date(myString, strategy: .iso8601).print(error.localizedDescription) rather than showing an alert or similar.if let value { shorthand over if let value = value {.if and switch can be used as expressions when returning values and assigning to variables.For example, this kind of code:
var tileColor: Color {
if isCorrect {
return .green
} else {
return .red
}
}
Should be written like this:
var tileColor: Color {
if isCorrect {
.green
} else {
.red
}
}
async/await equivalents and older closure-based variants, always prefer the async/await versions.DispatchQueue.main.async(), DispatchQueue.global(), etc.). Always use modern Swift concurrency (async/await, actors, Task).Task.sleep(nanoseconds:); use Task.sleep(for:) instead.@MainActor, unless the project is configured to use MainActor default actor isolation.@Sendable violations and data races.MainActor.run(), check whether the project has its default actor isolation set to Main Actor first, because MainActor.run() might not be needed.Task.detached() is often a bad idea. Check any usage extremely carefully.