Multiplatform template with watchOS?

Is it possible to add a watchOS target to the Multiplatform app template in Xcode? By default I only see iOS and macOS listed and when I try to add a watchOS target app I get a whole new App. Is this intended or am I missing some proper way to add a watchOS app?

Replies

I was struggling with the same question, but I think I found a solution.

Looks like after adding a target, you need to go to the shared folder and under each file, go to the identity and type area and add the new target to that file's attributes. I put it down in my response to my question below.

apple forums link: https://developer.apple.com/forums/thread/666877

Hope that helps!
In case you did not see the steps on the other post, this is how to add the Watch App and get it configured correctly.
  1. Create a Multiplatform project.

  2. In the project tree, select the project root node. On the General tab, click the "+" to add a Target. Choose "Watch App." IMPORTANT: Name the product the same as the existing macOS and iOS product name.

  3. If you want the same ContentView for your Watch App, in the WatchKit Extension files, delete the ContentView.swift. Choose "Move to Trash."

  4. To use the shared ContentView for your Watch App, in the "Shared" folder, select the ContentView.swift file. In the first tab on the right pane in Xcode, in Target Membership, check the WatchKit Extension target to include it. At this point, you have an Independent Watch App that is not a companion of your iOS App.

  5. In the folder for the WatchKit App, select the Info.plist. Add a new key named "WKCompanionAppBundleIdentifier" of Type "String" with Value equal to the Bundle Identifier of the iOS App in your project.

  6. In the folder for the WatchKit Extension, select the Info.plist. Select the key named "App is only available as a standalone watchOS app" and change it to "App can run independently of companion iPhone app."

  7. In the project tree, select the project root node. On the General tab, select the iOS target. In the "Frameworks, Libraries, and Embedded Content" section, click the "+" button to add an item. Add the WatchKit App.app item from your project.

  • This doesn't work anymore. In step 2 there is no Watch app as the option. If I choose add target from the File menu I cannot use the same name as suggested in step 2.

    New instructions would be appreciated.

Add a Comment

I tried this with Xcode 14.2 but got this message: "Project" already exists. The project "Project" already contains a target named "Project". Please choose a different name.

This is what allowed me to add a WatchOS app to a Multiplatform project and share the SwiftUI app lifecycle and root views.

  1. File > New > Target…
  2. Under the WatchOS tab select App and press Next.
  3. Set the product name (we'll change this later). You'll probably want to set your watch app to be "Watch App for Existing iOS App" for this workflow (note that there's a later step if you want to allow the watch app to run independently of the iOS app). Click Finish.

  1. Select your .xcodeproj and you'll see a new Watch App target (and test targets if you elected for them) in the Targets section of the sidebar.

  1. Select the Watch App and on the General tab you can change the Display Name to match your other targets.
  2. Click the Watch App target again while it's highlighted to edit the name. I changed mine from "MedicineWatch Watch App" to just "Medicine Watch App".

  1. If you want to allow the watch app to run independently of the iOS app: In the Watch App target's Build Settings tab, find Info.plist Values and change "App Can Run Independentlv of Companion iPhone App" to Yes.

  1. To have the watch app use the same shared SwiftUI app lifecycle file and root view: delete the [Name]App.swift and ContentView.swift files in the Watch App directory. Then add the watch target to the lifecycle file and any views using the inspector. (If you included Core Data with the template then you'll also need to add the watch target to the persistence logic and model definition files.)

  1. You should now be able to run your multiplatform app on the WatchOS simulator.

I've had a few directory renames cause errors but Xcode was able to point me to where I needed to update configurations.

Hope this saves some trial and error :)

  • Magnificent, thank you!

Add a Comment