11

I have an iOS app with a Apple Watch extension. I downloaded Xcode 14 and have the warning:

WatchKit storyboards are deprecated in watchOS 7.0 and later. Please migrate to SwiftUI and the SwiftUI Lifecycle.

I'm all for this migration, in fact, my initial hosting controller returns a SwiftUI view. But I can't find anywhere how to actually migrate to a SwiftUI Lifecycle from WatchKit. Does anyone know how to do this?

I'm completely fine with deleting my WatchKit storyboards since their unused other than pointing to the initial controller. Here's my initial controller code if it helps:

import WatchKit
import Foundation
import SwiftUI

class HostingController: WKHostingController<AnyView> {
    override var body: AnyView {
        return AnyView(WatchHomeUI())
    }
}
fphelp
  • 1,544
  • 1
  • 15
  • 34
  • 2
    Créate a new Xcode project and make sure you start matching the app delegate, the YourAppApp file with the main wrapper and the info.plist – lorem ipsum Sep 09 '22 at 11:20

1 Answers1

2

You can simply replace the following files:

  • Interface.strings
  • Interface.storyboard
  • HostingerController.swift

by

  • YourWatchAppTargetName.swift with something like this as content:
import SwiftUI

@main
struct YourWatchAppTargetName: App {
    var body: some Scene {
        WindowGroup {
            ContentView()
        }
    }
}

and don't forget to remove @main from your ExtensionDelegate.swift file.