iOS Today Widget 与主应用共享源文件

iOS Today Widget share source file with main application

我在我的 Xcode 工作区中添加了一个 Today Extention Widget 项目,我想使用主应用程序中的一些源文件,所以我在这个文件上标记了 "target membership"。问题是 Xcode 链接器在编译主应用程序时失败并出现 重复符号 错误。那么在主应用程序和小部件之间共享源文件的正确方法是什么?

您可以使用 Frameworks 在您的 Host AppApp Extension 之间共享 code/files。

You can create an embedded framework to share code between your app extension and its containing app. For example, if you develop an image filter for use in your Photo Editing extension as well as in its containing app, put the filter’s code in a framework and embed the framework in both targets.

有关Host AppApp Extension之间共享场景的更多信息,请参阅:https://developer.apple.com/library/content/documentation/General/Conceptual/ExtensibilityPG/ExtensionScenarios.html#//apple_ref/doc/uid/TP40014214-CH21-SW1