As you begin customizing StarterAppKit for your own purposes, you’ll likely want to tailor the initial views presented to your users. One of the first places you might start is by modifying or replacing the Base/Home view.
Replacing the Base/Home View
By default, the Base view is included as an example entry point to various pre-built views and features in StarterAppKit. If a user is authenticated, this view acts as the “home” screen; if not, the user sees the authentication screen. The Base view also serves as the primary entry point for authenticated deep links, helping to route the user to the correct destination based on incoming URLs.
Where the Base View Is Introduced
The Base view is introduced in InitialView.swift, which determines what to present based on the user’s authentication state. Here’s the relevant snippet:
The Role of the Base View
Authenticated Home Screen: The Base view is what the user sees if they are already logged in. By default, it acts as your "home" screen.
Deep Linking Entry Point: When a user opens a deep link that requires authentication (like myapp://home/profile), the Base view may be responsible for initiating navigation to the correct subview.
Customization Opportunity: If the default layout or navigation logic in BaseView.swift does not align with your desired architecture, you can modify it directly or replace it entirely.
Two Ways to Replace the Base/Home View
Edit BaseView.swift directly:
If you’re mostly satisfied with the current setup, you can open BaseView.swift and remove or adjust code that’s not needed.
Create Your Own View and Update InitialView.swift:
If you’d prefer a fresh start, create a new SwiftUI view (e.g. MyCustomHomeView.swift) and then replace BaseView(remainingPaths: ...) calls in InitialView.swift with your custom view.
Example: Replacing the BaseView
Let’s assume you’ve created a new home screen view called MyCustomHomeView.swift.
remainingPaths: An array of path segments extracted from a deep link (e.g. myapp://home/profile → ["home", "profile"])
nextDestination: A computed property that identifies the next path segment and the remaining segments after it.
shouldNavigate: A state variable that triggers navigation once the view appears and a next destination is detected.
CustomNavigationLink: Used to initiate navigation to the target view identified by the next deep link path.
Integrating Your Custom Home View
In InitialView.swift, replace the references to BaseView with MyCustomHomeView. If the user is authenticated and there are no deep link paths, your custom home view will appear by default. If there are deep link paths, MyCustomHomeView uses the logic above to navigate to the correct destination.
Testing Your Changes
Run in Simulator: If the user is authenticated, the simulator should now show MyCustomHomeView.
Deep Link Testing: Trigger a deep link such as myapp://home/profile. Your custom home view should automatically navigate to UserProfileView, thanks to the deep linking logic you replicated.
Auth Flow Check: Sign out and back in to ensure that the authentication and navigation flows work as intended.