View Changing in Simulator not Preview

I've noticed that these lines of code, whenever I run them in the simulator, it would preview the changes in view. However, whenever I run them in the Xcode preview, it wouldn't change the view at all? I'm quite confused about this.
import SwiftUI

struct IntroductionView: View {

@State private var showSplashScreen = true

var body: some View {
if showSplashScreen {
SplashScreenView(showSplashScreen: $showSplashScreen)
} else {
WelcomeView()
}
}
}

struct IntroductionView_Previews: PreviewProvider {
static var previews: some View {
IntroductionView()
}
}
import SwiftUI

struct IntroductionView: View {

@State private var showSplashScreen = true

var body: some View {
if showSplashScreen {
SplashScreenView(showSplashScreen: $showSplashScreen)
} else {
WelcomeView()
}
}
}

struct IntroductionView_Previews: PreviewProvider {
static var previews: some View {
IntroductionView()
}
}
4 Replies
iwontchill
iwontchillOP16mo ago
@outsharded - Do you know?
outsharded
outsharded16mo ago
#how-to-ask
iwontchill
iwontchillOP16mo ago
@Coach
</The |  AR  | Coder >
LOL here are a few suggestions. First of all, just know Xcode can be weird sometimes and it can 100% be not directly related to your code. Build and Refresh: Sometimes, the SwiftUI preview might not update automatically. Try stopping the preview and then re-building the project. You can also try clicking the "Resume" button in the preview canvas to refresh the preview manually. Clean Build Folder: Go to "Product" in the Xcode menu while holding the Option key, and you'll see the "Clean Build Folder" option. Then, rebuild the project and check if the preview updates. Restart Xcode: Check for Errors: Make sure there are no errors or warnings in your code that could be preventing the preview from updating. Check the console for any error messages that might provide clues about what's going wrong. Try Different Preview Devices Update Xcode Create a new project to see if the issue persists there with the same code It could be due to a bug in Xcode itself.
Want results from more Discord servers?
Add your server