1

I am trying to implement the new Commands for iPadOS 15 and to do that you have to declare them in the App like the following example

@main
struct I_FeelApp: App {
    @State private var sceneCommands = GlobalCommands()

    var body: some Scene {
        
        WindowGroup {
            ContentView(globalCommands: sceneCommands)
        }
        .commands(content: { sceneCommands.commands })
    }
}

The problem I have with this approach is that the object GlobalCommands() is created for the entire App not for every scene, so a change in one of the scenes will modify all of them like in the following example

GIF demonstrating issue

I have tried to create a new scene struct and create there the commands, but SwiftUI creates it for the App, no for the Scene

Creating it in a normal View doesn't work, because I can't add commands to the a View, only to a Scene

George
  • 25,988
  • 10
  • 79
  • 133
Zapata
  • 21
  • 3

1 Answers1

1

I contacted apple about it and I found out an answer, my problem was that I had no idea about the property wrapper @SceneStorage and @FocusedBinding

So once I knew those where options I just created them and used them and it worked.

Here's a link to Apple's Code-Along about it.

Invalid Memory
  • 717
  • 7
  • 23
Zapata
  • 21
  • 3