Caminhos de navegação programática
Controle a navegação com um caminho navigationDestination.
Caminhos de navegação programática é uma aula grátis de SwiftUI Academy no CoddyKit. Esta é a aula 4 de 4. Você pode ler a aula completa abaixo gratuitamente — depois pratica ao vivo no navegador com um editor de código integrado e um tutor de IA 24/7. Faz parte do caminho de aprendizado de SwiftUI Academy, e seu progresso é sincronizado entre a web e o app CoddyKit. O curso de SwiftUI Academy inclui 4 aulas no total.
Partes desta aula ainda não foram traduzidas e aparecem em inglês.
Navigating From Code
Sometimes a tap is not enough. After saving a form you may want to jump screens yourself. SwiftUI lets you drive the stack from code. ⚙️
A Path You Control
Give NavigationStack a path binding. This array is the live list of screens currently pushed, and editing it changes navigation instantly.
@State private var path = NavigationPath()
NavigationStack(path: $path) { HomeView() }Push by Appending
Append a value to the path and SwiftUI pushes the matching screen. No tap needed, just change the array.
path.append(book)Routing the Value
A navigationDestination maps each value type in the path to a view, so appended data knows which screen to become.
.navigationDestination(for: Book.self) { book in
DetailView(book: book)
}Pop With Remove
Removing the last element pops a screen, exactly like the back button. You stay in full control of the stack from code.
path.removeLast()Jump Home Instantly
To return all the way to the root, empty the path. Every pushed screen disappears at once, perfect for a Done button. 🏠
path.removeLast(path.count)Deep Linking
Because the path is just data, you can build it from a URL or notification, pushing several screens so users land deep inside the app.
NavigationPath Holds Mixed Types
A NavigationPath can store values of different types together, letting one stack route books, users, and settings without a shared enum.
Or Use a Typed Array
If every screen shares one type, a plain typed array works as the path and reads a little more clearly than NavigationPath.
@State private var path: [Book] = []State Drives the Stack
Navigation becomes state. The visible screens always mirror the path array, so your UI stays predictable and easy to reason about.
Test and Restore
Since the path is plain data, you can save it and restore it, recreating exactly where the user left off when they reopen the app.
Quick Check
What happens when you append a value to a NavigationStack path?
Recap: Programmatic Paths
You bind a path to NavigationStack and push or pop screens by editing that array, turning navigation into predictable, testable state. 🎉
Perguntas Frequentes
A aula “Caminhos de navegação programática” é grátis?
Sim — o texto completo de “Caminhos de navegação programática” é grátis para ler aqui na web. Para praticá-la interativamente (um editor de código integrado e um tutor de IA 24/7) e desbloquear o restante do curso de SwiftUI Academy, atualize para CoddyKit PRO. O curso de SwiftUI Academy inclui 4 aulas no total.
O que vou aprender em “Caminhos de navegação programática”?
Controle a navegação com um caminho navigationDestination. Você pratica SwiftUI Academy com código prático que executa diretamente no navegador, e um tutor de IA 24/7 responde suas dúvidas enquanto trabalha na aula.
Preciso ter experiência prévia para começar SwiftUI Academy?
Nenhuma experiência prévia é necessária. SwiftUI Academy no CoddyKit é estruturado para alunos iniciantes até avançados, então você pode começar aqui ou desde o início e aprender no seu ritmo. Esta é a aula 4 de 4.
Quanto tempo leva a aula “Caminhos de navegação programática”?
A maioria das aulas CoddyKit leva cerca de 5–10 minutos. Cada uma é compacta e interativa, então você faz progresso constante e retoma exatamente de onde parou entre web e app.
Posso escrever e executar código nesta aula de SwiftUI Academy?
Sim. Cada aula de SwiftUI Academy inclui um editor de código integrado, então você escreve e executa código real direto no navegador e recebe feedback de IA instantaneamente — nenhuma configuração local necessária.
Todas as aulas deste curso
- Abrindo telas com NavigationLink
- Passando dados para visualizações de detalhes
- Barra de ferramentas e título de navegação
- Caminhos de navegação programática