0

Previously in WatchKit we could tell a certain InterfaceController to present itself using .becomeCurrentPage, how can we do it in Swift UI?

In WatchKit for example I would:

  // handle notification
    @objc func respondToWaterlock(_ notification: NSNotification) {
        self.becomeCurrentPage()
    }
GarySabo
  • 5,806
  • 5
  • 49
  • 124

1 Answers1

1

there is no equivalent for becomeCurrentPage method in SwiftUI. You can update your State or ViewModel to achieve a similar result. for example:

enum Pages {
    case home
    case settings
}

struct MyView: View {
    
    @State var selectedPage: Pages = .home
    
    var body: some View {
        Group {
            if self.selectedPage == .home {
                Text("Home")
            } else if self.selectedPage == .settings {
                Text("Settings")
            }
        }
    }
    
}

You should just update the selectedPage state variable to change the page.

Mohammad Rahchamani
  • 5,002
  • 1
  • 26
  • 36