Programowe ścieżki nawigacji
Proszę sterować nawigacją za pomocą ścieżki navigationDestination.
Programowe ścieżki nawigacji to bezpłatna lekcja SwiftUI Academy na CoddyKit. To lekcja 4 z 4. Możesz przeczytać całą lekcję poniżej za darmo — a potem ćwiczyć ją interaktywnie w przeglądarce z wbudowanym edytorem kodu i tutorem AI dostępnym 24/7. To część ścieżki edukacyjnej SwiftUI Academy, a Twój postęp synchronizuje się między webem a aplikacją CoddyKit. Kurs SwiftUI Academy zawiera 4 lekcji w sumie.
Części tej lekcji nie zostały jeszcze przetłumaczone i są wyświetlane po angielsku.
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. 🎉
Często zadawane pytania
Czy lekcja „Programowe ścieżki nawigacji” jest bezpłatna?
Tak — pełny tekst „Programowe ścieżki nawigacji” jest dostępny za darmo tutaj w sieci. Aby ćwiczyć ją interaktywnie (wbudowany edytor kodu i tutor AI dostępny 24/7) i odblokować resztę kursu SwiftUI Academy, przejdź na CoddyKit PRO. Kurs SwiftUI Academy zawiera 4 lekcji w sumie.
Co nauczysz się w „Programowe ścieżki nawigacji”?
Proszę sterować nawigacją za pomocą ścieżki navigationDestination. Ćwiczysz SwiftUI Academy z praktycznym kodem, który uruchamiasz bezpośrednio w przeglądarce, a tutor AI dostępny 24/7 odpowiada na Twoje pytania podczas pracy nad lekcją.
Czy potrzebuję doświadczenia, aby zacząć SwiftUI Academy?
Nie wymagamy żadnego doświadczenia. SwiftUI Academy w CoddyKit jest strukturyzowany dla początkujących i zaawansowanych użytkowników, więc możesz zacząć tutaj lub od początku i uczyć się w swoim tempie. To lekcja 4 z 4.
Ile czasu zajmuje lekcja „Programowe ścieżki nawigacji”?
Większość lekcji CoddyKit trwa około 5–10 minut. Każda lekcja to mały, interaktywny krok, dzięki czemu robisz systematyczne postępy i zawsze wracasz dokładnie do tego samego miejsca — na webie i w aplikacji.
Czy mogę pisać i uruchamiać kod w tej lekcji SwiftUI Academy?
Tak. Każda lekcja SwiftUI Academy zawiera wbudowany edytor kodu, więc piszesz i uruchamiasz prawdziwy kod bezpośrednio w przeglądarce i od razu otrzymujesz sprzężenie zwrotne od AI — bez konfiguracji na komputerze.
Wszystkie lekcje w tym kursie
- Otwieranie ekranów za pomocą NavigationLink
- Przekazywanie danych do widoków szczegółów
- Pasek narzędzi i tytuł nawigacji
- Programowe ścieżki nawigacji