简体   繁体   English

将目标添加到 iOS/macOS 多平台项目 (Xcode 12)

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

Xcode 12 (Beta) introduced the new multi-platform project template for iOS/macOS apps. Xcode 12 (Beta) 为 iOS/macOS 应用程序引入了新的多平台项目模板。 If I add a new target (File -> New -> Target... -> Watch App), Xcode adds a new app project to the existing one.如果我添加一个新目标(文件 -> 新建 -> 目标... -> 监视应用程序),Xcode 会在现有应用程序项目中添加一个新应用程序项目。 My preference is, that the watchOS-Project uses the shared folder, like the iOS and macOS app.我的偏好是 watchOS-Project 使用共享文件夹,例如 iOS 和 macOS 应用程序。

My question is, how to integrate another app project, like watchOS or tvOS, to an existing multi-platform project?我的问题是,如何将另一个应用程序项目(如 watchOS 或 tvOS)集成到现有的多平台项目中? As a reference, I found a GitHub-Project, which integrated watchOS and tvOS in a multi-platform project: https://github.com/jordansinger/SwiftUI-Kit作为参考,我找到了一个 GitHub-Project,它在一个多平台项目中集成了 watchOS 和 tvOS: 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"为 iOS 平台创建新项目并将其命名为“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" Xcode 会询问您是否要重命名所有其他项目文件 -> 单击“不重命名”
  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).单击底部的“+”和 select 其他平台(例如 tvOS)的应用程序模板。 Set the product name to "tvOS" and click on "Finish".将产品名称设置为“tvOS”,然后单击“完成”。
  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. Go 遍历所有目标并将每个目标的捆绑标识符更改为正确的产品名称。
  6. Create the following folders by right-clicking on the project file and choosing "New Group": Shared, Shared Tests, Shared UITests.通过右键单击项目文件并选择“新建组”来创建以下文件夹: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).现在您将要在所有平台之间共享的文件从平台文件夹之一移动到“共享”文件夹(例如 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": Go 通过“Shared”文件夹中的所有文件和 select “Target Membership”下的其他平台: 在此处输入图像描述

9. Do the same for the Tests und UITests 9. 对 Tests 和 UITests 做同样的事情

It's cumbersome, but it works.这很麻烦,但它有效。 Maybe somebody else finds a better way...也许其他人会找到更好的方法...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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