How do I get my WatchOS target to use the Shared folder in Multi Platform Template?

Hi everyone,

When I add WatchOS as a target to my multi platform SwiftUI project, it creates its own ContentView within the Watchkit Extension folder. It does not seem to be able to access any views within the "Shared" folder in the multi platform App template, leaving me with two Content Views in the project.

Does anyone know how to add a WatchOS target and have it use the shared files? Can this be done?

I was encouraged because the App Essentials WWDC20 video implies WatchOS can be used with this template as they have a screenshot example, but so far haven't had success in duplicating it.
Answered by Frameworks Engineer in 647453022
Assuming you want your iOS app to be a companion of your watchOS app, there are actually a few steps. This should get you going (starting from scratch, so pick up from where you are now):
  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. In the WatchKit Extension files, delete the ContentView.swift. Choose "Move to Trash."

  4. 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.

Though I think I have found a solution, I am not sure if it is the most efficient/best path

This stack overflow link helped:
Stack Overflow similar question

Essentially, after creating a Multi Platform App in SwiftUI:
  1. Add a new Target to the project (in my case watchOS stand alone)

  2. Click on "Content View" in the shared folder, and under Identity and Type on the far right, add the new target (in my case, watchOS WatchKit Extension)

  3. Delete Content View within the new target folder

That will Build and run on my watchOS simulator! However, I still get some warnings:
  • Warning: Error creating LLDB target at path ... using an empty LLDB target which can cause slow memory reads from remote devices.


Though this gets me going a bit further, if anyone has a more efficient/better explained approach, please feel free to chime in.
Accepted Answer
Assuming you want your iOS app to be a companion of your watchOS app, there are actually a few steps. This should get you going (starting from scratch, so pick up from where you are now):
  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. In the WatchKit Extension files, delete the ContentView.swift. Choose "Move to Trash."

  4. 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.

How do I get my WatchOS target to use the Shared folder in Multi Platform Template?
 
 
Q