Casey Perkins
Casey Perkins

Reputation: 1942

possible to instantiate WKInterfaceController in SwiftUI Watch project?

I have a project in which I have run into a limitation of SwiftUI on the Apple Watch. My proposed solution was to instantiate a WKInterfaceController to perform the needed functionality, and then return to using SwiftUI views. Is this possible? I tried to wrap my controller in a WKInterfaceObjectRepresentable object, but there doesn't seem to way to instantiate the interface controller from a Storyboard, as is possible on iOS according to this similar case:

How to add Storyboard ViewController into SwiftUI Project?

But Xcode tells me, "Cannot find UIStoryboard in scope"

Is there a way to create an InterfaceController from SwiftUI? Or perhaps I need to use a WKHostingController for my whole Watch project, so as to have access to the option of using InterfaceController objects?

Thanks.

enter image description here

Upvotes: 5

Views: 1032

Answers (1)

crafterm
crafterm

Reputation: 1881

You can navigate to an existing interface controller defined in a watchOS storyboard from SwiftUI by using NavigationLink with the destinationName:label: arguments, see here.

destinationName is the identifier used in the storyboard for that interface controller, eg:

NavigationLink(destinationName: "MyInterfaceControllerIdentifier") {
  Text("Go")
}

Upvotes: 0

Related Questions