How to conditionally show a SwiftUI Scene on macOS?

I have an Onboarding Window/Scene I want to appear on the first launch of the app, or when a use clicks a menu command.

Using an AppStorage with a boolean value would be perfect, but when I try to add an if in my SceneBuilder I get the following error: Closure containing control flow statement cannot be used with function builder 'SceneBuilder'.

Code Block swift
import SwiftUI
@main
struct MyApp: App {
  @AppStorage("tutorialVisible") var tutorialVisible: Bool = true
  var body: some Scene {
    MainScene()
    if tutorialVisible {
      TutorialScene()
    }
  }
}



How can this be done?
In Xcode Beta 6 there's a new API added to Scene:

Code Block swift
@available(iOS 14.0, macOS 11.0, *)
public func handlesExternalEvents(matching conditions: Set<String>) -> some Scene

Based on the doc comments I don't think this will provide the behavior I'm looking for. I'll report back after macOS Beta 6 is released and I play around with it though.
This is an excellent question. I have not found any answers. Just hoping to bump this.
Code Block
@main
struct OscillatingEmbersApp: App {
    var model: AppModel = AppModel.restoreFromUserDefaults()
    var body: some Scene {
        WindowGroup {
            computedView()
        }
    }
    func computedView() -> some View {
        model.increment()
        model.saveToUserDefaults()
        if model.isEven() {
            return AnyView(EvenView())
        } else {
            return AnyView(OddView())
        }
    }
}
class AppModel: Codable {
    static let StorageKey = "AppModel.StorageKey"
    var count: Int = 0
    init(count: Int) {
        self.count = count
    }
    func increment() {
        count += 1
    }
    func isEven() -> Bool  {
        count % 2 == 0
    }
    static func restoreFromUserDefaults() -> AppModel {
        let defaults = UserDefaults.standard
        let count = defaults.integer(forKey: AppModel.StorageKey)
        return AppModel(count: count)
    }
    func saveToUserDefaults() {
        let defaults = UserDefaults.standard
        defaults.set(self.count, forKey: AppModel.StorageKey)
    }
}

So I tried this in Xcode 12 on an emulator iPhone 12 Pro Max running 14.0. Each time I launch the app, I get an odd then even screen on successive launches.

So I would add something that saves if the user has done onboarding then return the correct view?


could you try this:

Code Block
   var body: some Scene {
   tutorialVisible ? TutorialScene() : MainScene()
  }

How to conditionally show a SwiftUI Scene on macOS?
 
 
Q