swiftui-view-refactor
Refactor and review SwiftUI view files for consistent structure, dependency injection, and Observation usage. Use when asked to clean up a SwiftUI view’s layout/ordering, handle view models safely (non-optional when possible), or standardize how dependencies and @Observable state are initialized and passed.
Security Assessment
About swiftui-view-refactor
The 'swiftui-view-refactor' skill is designed to help developers standardize and improve the structure of SwiftUI views, ensuring consistency in layout, dependency injection, and Observation usage. It addresses common issues in SwiftUI development, such as disorganized view bodies, improper handling of view models, and incorrect dependency injection patterns. By applying consistent coding practices and patterns, this skill streamlines the development process and results in cleaner, more maintainable SwiftUI code.
FAQ
When should I use this skill?
This skill should be used when you need to clean up SwiftUI views, refactor large or messy view bodies, or handle view models and dependencies more safely and consistently. It's particularly useful for enforcing MV (Model-View) patterns and organizing view layouts.
Can this skill be used with existing view models?
Yes, this skill helps to refactor existing view models by making them non-optional and ensuring that dependencies are properly passed through the view's `init` method. It avoids introducing new view models unless explicitly required.
Is this skill compatible with all SwiftUI projects?
The skill is applicable to any SwiftUI project, particularly those where views need to be refactored for better readability, maintainability, and structure. However, it assumes some basic understanding of SwiftUI patterns and does not create new APIs or functions beyond standard SwiftUI practices.
Are there any limitations to using this skill?
The skill does not introduce any new view models or complex patterns unless required. It mainly focuses on refactoring existing views and ensuring they adhere to consistent, best practices. It assumes a certain level of familiarity with SwiftUI concepts like `@State`, `@Environment`, and `@Observable`.
Install swiftui-view-refactor
Quick Setup:
- Copy the skill folder to
.claude/skills/ - Claude will automatically detect and use the skill
Repository
steipete/agent-scripts