TEAM LICENSES: Save money and learn new skills through a Hacking with Swift+ team license >>

SOLVED: How to change the start page of an app?

Forums > SwiftUI

I have a settings page that allows users to select a default start page for the app, which is saved into UserDefaults. I do not know how to set a custom start page instead of the default ContentView.

3      

You can use if and switch statements in Views now (in the new betas, that is), so you could have a switch that handles the possible values stored in UserDefaults and displays an appropriate view.

Another way is to have a function that returns a View based on the value from UserDefaults - if you place the function call in your main View it will return the View from the function and display that.

3      

Hacking with Swift is sponsored by RevenueCat.

SPONSORED Take the pain out of configuring and testing your paywalls. RevenueCat's Paywalls allow you to remotely configure your entire paywall view without any code changes or app updates.

Learn more here

Sponsor Hacking with Swift and reach the world's largest Swift community!

Archived topic

This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.

All interactions here are governed by our code of conduct.

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.