swiftui-view-refactor
O que ela faz
Esta skill reestrutura o código de views SwiftUI para deixá-lo mais fácil de ler e manter. Ela serve para desenvolvedores iOS que têm views grandes ou bagunçadas.
Quando usar
- ✓Quando um arquivo de view SwiftUI cresceu muito e ficou difícil de ler.
- ✓Quando o body de uma view está longo demais e deveria ser dividido em partes menores.
- ✓Quando você quer que o estado e as dependências de uma view sejam configurados de forma consistente.
Link da skill
https://github.com/steipete/agent-scripts/blob/main/skills/swiftui-view-refactor/SKILL.mdCopie e cole na sua IA (Claude, ChatGPT ou Cursor) pedindo para seguir as instruções.
Como usar
O jeito mais fácil: copie a mensagem e cole na sua IA. Ela lê a skill e segue as instruções.
Mensagem pronta para colar
Para Claude Code, Codex ou Cursor: rode na pasta do projeto e a skill fica instalada.
Baixe o SKILL.md e coloque na pasta de skills do seu agente.
Exemplo do que pedir para a IA
“Este arquivo de tela SwiftUI está enorme. Refatore em views menores com uma estrutura limpa.”
5 skills novas por semana. 1 minuto de leitura.
Como funciona
O agente aplica uma ordem consistente às propriedades e ao código da view, divide os bodies grandes em subviews e prefere injeção simples de estado e de environment em vez de view models extras.
Conteúdo técnico (SKILL.md original)
Texto original do autor, em inglês, direto do GitHub.
SwiftUI View Refactor
Attribution: copied from @Dimillian’s Dimillian/Skills (2025-12-31).
Overview
Apply a consistent structure and dependency pattern to SwiftUI views, with a focus on ordering, Model-View (MV) patterns, careful view model handling, and correct Observation usage.
Core Guidelines
1) View ordering (top → bottom)
- Environment
private/publiclet@State/ other stored properties- computed
var(non-view) initbody- computed view builders / other view helpers
- helper / async functions
2) Prefer MV (Model-View) patterns
- Default to MV: Views are lightweight state expressions; models/services own business logic.
- Favor
@State,@Environment,@Query, andtask/onChangefor orchestration. - Inject services and shared models via
@Environment; keep views small and composable. - Split large views into subviews rather than introducing a view model.
3) Split large bodies and view properties
- If
bodygrows beyond a screen or has multiple logical sections, split it into smaller subviews. - Extract large computed view properties (
var header: some View { ... }) into dedicatedViewtypes when they carry state or complex branching. - It's fine to keep related subviews as computed view properties in the same file; extract to a standalone
Viewstruct only when it structurally makes sense or when reuse is intended. - Prefer passing small inputs (data, bindings, callbacks) over reusing the entire parent view state.
Example (extracting a section):
var body: some View {
VStack(alignment: .leading, spacing: 16) {
HeaderSection(title: title, isPinned: isPinned)
DetailsSection(details: details)
ActionsSection(onSave: onSave, onCancel: onCancel)
}
}
Example (long body → shorter body + computed views in the same file):
var body: some View {
List {
header
filters
results
footer
}
}
private var header: some View {
VStack(alignment: .leading, spacing: 6) {
Text(title).font(.title2)
Text(subtitle).font(.subheadline)
}
}
private var filters: some View {
ScrollView(.horizontal, showsIndicators: false) {
HStack {
ForEach(filterOptions, id: \.self) { option in
FilterChip(option: option, isSelected: option == selectedFilter)
.onTapGesture { selectedFilter = option }
}
}
}
}
Example (extracting a complex computed view):
private var header: some View {
HeaderSection(title: title, subtitle: subtitle, status: status)
}
private struct HeaderSection: View {
let title: String
let subtitle: String?
let status: Status
var body: some View {
VStack(alignment: .leading, spacing: 4) {
Text(title).font(.headline)
if let subtitle { Text(subtitle).font(.subheadline) }
StatusBadge(status: status)
}
}
}
4) View model handling (only if already present)
- Do not introduce a view model unless the request or existing code clearly calls for one.
- If a view model exists, make it non-optional when possible.
- Pass dependencies to the view via
init, then pass them into the view model in the view'sinit. - Avoid
bootstrapIfNeededpatterns.
Example (Observation-based):
@State private var viewModel: SomeViewModel
init(dependency: Dependency) {
_viewModel = State(initialValue: SomeViewModel(dependency: dependency))
}
5) Observation usage
- For
@Observablereference types, store them as@Statein the root view. - Pass observables down explicitly as needed; avoid optional state unless required.
Workflow
- Reorder the view to match the ordering rules.
- Favor MV: move lightweight orchestration into the view using
@State,@Environment,@Query,task, andonChange. - If a view model exists, replace optional view models with a non-optional
@Stateview model initialized ininitby passing dependencies from the view. - Confirm Observation usage:
@Statefor root@Observableview models, no redundant wrappers. - Keep behavior intact: do not change layout or business logic unless requested.
Notes
- Prefer small, explicit helpers over large conditional blocks.
- Keep computed view builders below
bodyand non-view computed vars aboveinit. - For MV-first guidance and rationale, see
references/mv-patterns.md.
Perguntas frequentes
Ela adiciona um view model a cada tela?
Não. A skill prefere um padrão leve, em que as views ficam simples e os models cuidam da lógica de negócio.
Onde as propriedades devem ficar em um arquivo de view?
Em uma ordem fixa, começando pelos valores de environment e depois pelas propriedades armazenadas.
Quando um auxiliar deve virar uma view própria?
Quando ele carrega estado ou ramificações complexas, ou quando a reutilização faz sentido estrutural.
Detalhes
Descrição original do autor
SwiftUI view refactor/review: layout, DI, Observation, view models.
repo: steipete/agent-scripts
Popularidade
- Estrelas no GitHub
- 7,4 mil
- Posição no ranking
- #13251
- Licença
- MIT
- Atualizada em
- 30/10/2026
Comentários
- …
Mais skills deste repositório
beeper
7,4 milAjuda seu agente a pesquisar o seu histórico local de conversas do Beeper para encontrar mensagens e descobrir a qual conversa ou contato uma pista vaga se refere.
cloudflare-registrar
7,4 milAjuda seu agente a consultar preços e disponibilidade de domínios no Cloudflare Registrar, e a registrar ou listar domínios com uma etapa de confirmação.
codexbar
7,4 milAjuda seu agente a verificar quanto uso você ainda tem em serviços de IA como Codex, Claude e Kimi, incluindo limites, créditos e horários de renovação.
create-cli
7,4 milAjuda seu agente a desenhar os comandos, as opções, os textos de ajuda, a saída e os erros de uma ferramenta de linha de comando, para que ela funcione tanto para pessoas quanto para scripts.
Skills parecidas
android-clean-architecture
280 milFaz seu agente organizar projetos Android de forma eficiente. Ele estrutura o código para facilitar a manutenção e o desenvolvimento de novos recursos.
compose-multiplatform-patterns
280 milAjuda seu agente a usar Compose Multiplatform e Jetpack Compose em projetos KMP. Cobre estado, navegação, temas e performance.
dart-flutter-patterns
280 milFaz seu agente escrever código para apps Dart e Flutter. Ele usa padrões modernos para criar apps robustos e fáceis de gerenciar.