简体   繁体   中英

Add target to iOS/macOS Multi-Platform Project (Xcode 12)

Xcode 12 (Beta) introduced the new multi-platform project template for iOS/macOS apps. If I add a new target (File -> New -> Target... -> Watch App), Xcode adds a new app project to the existing one. My preference is, that the watchOS-Project uses the shared folder, like the iOS and macOS app.

My question is, how to integrate another app project, like watchOS or tvOS, to an existing multi-platform project? As a reference, I found a GitHub-Project, which integrated watchOS and tvOS in a multi-platform project: https://github.com/jordansinger/SwiftUI-Kit

I also struggled adding an new target for an additional platform. I ended up doing it like this:

  1. Create new project for iOS platform and name it "iOS"
  2. Rename project (first file in the file list) to your product name. Xcode will ask you if you want to rename all other project files -> click on "Don't rename"
  3. While the project file is still selected, you see a column with the targets. Click on the "+" on the bottom and select the app template for an other platform (eg tvOS). Set the product name to "tvOS" and click on "Finish".
  4. Add more platforms if needed.
  5. Go through all targets and change the Bundle Identifier for each of them to the correct product name.
  6. Create the following folders by right-clicking on the project file and choosing "New Group": Shared, Shared Tests, Shared UITests.
  7. Now you move the files you want to share between all platforms from one of the platform folders to the "Shared" folder (eg ContentView.swift). Delete all those files from the other platforms folders.
  8. Go through all the files in the "Shared" folder and select the other platforms under "Target Membership": 在此处输入图像描述

9. Do the same for the Tests und UITests

It's cumbersome, but it works. Maybe somebody else finds a better way...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM