プログラムによるナビゲーション パス
navigationDestination のパスでナビゲーションを制御します。
「プログラムによるナビゲーション パス」はCoddyKit上の無料SwiftUI Academyレッスンです。 これはレッスン4/4です。 下記で完全なレッスンを無料で読むことができます。その後、ブラウザ内の組み込みコードエディタと24時間対応のAIチューターでハンズオン演習できます。 これはSwiftUI Academy学習パスの一部であり、ウェブとCoddyKitアプリ全体で進捗が同期されます。 SwiftUI Academyコースには全4レッスンが含まれています。
このレッスンの一部はまだ翻訳されておらず、英語で表示されています。
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. 🎉
よくある質問
「プログラムによるナビゲーション パス」レッスンは無料ですか?
はい。「プログラムによるナビゲーション パス」の完全なテキストはこのウェブで無料で読めます。インタラクティブに演習し(組み込みコードエディタと24時間対応のAIチューター)、SwiftUI Academyコースの残りをアンロックするには、CoddyKit PROにアップグレードしてください。 SwiftUI Academyコースには全4レッスンが含まれています。
「プログラムによるナビゲーション パス」で何を学びますか?
navigationDestination のパスでナビゲーションを制御します。 ブラウザで直接実行するハンズオンコードでSwiftUI Academyを演習し、24時間対応のAIチューターがレッスンを進める中での質問に答えます。
SwiftUI Academyを始めるのに経験は必要ですか?
事前経験は必要ありません。CoddyKitのSwiftUI Academyは初級者から上級者向けに構成されているため、ここから始めるか最初から始めて、自分のペースで進むことができます。 これはレッスン4/4です。
「プログラムによるナビゲーション パス」レッスンにはどのくらい時間がかかりますか?
ほとんどのCoddyKitレッスンは約5~10分かかります。各レッスンはコンパクトでインタラクティブなので、着実に進歩し、ウェブとアプリ全体で正確に前回の場所から再開できます。
このSwiftUI Academyレッスンでコードを書いて実行できますか?
はい。すべてのSwiftUI Academyレッスンに組み込みコードエディタが含まれているため、ブラウザでリアルコードを書いて実行し、即座のAIフィードバックを取得できます。ローカル設定は不要です。
このコースのすべてのレッスン
- NavigationLink で画面を表示する
- 詳細ビューへのデータ受け渡し
- Toolbar とナビゲーション タイトル
- プログラムによるナビゲーション パス