在 Xcode 中为不同的目标使用相同的代码

问题描述:

我想在 Xcode 中为不同的目标使用相同的代码.我可以使用 Duplicate 方法创建目标,然后我也可以更改方案名称.

I want to use the same code for different target in Xcode. I am able to create the target using the Duplicate method and then I am able to change scheme name as well.

现在真正的场景来了,我想以集中方式使用我的代码,比如新目标,我不想复制和粘贴 Main.storyboard 和 xib,所以,理想情况下会发生什么,如果我会在一个地方更改任何内容,所有目标都会共享.但问题来了,``ViewControllerinMain.Storyboard` 持有主项目模块",因此,当我运行子目标时,它无法运行.

Now the real scenario comes, I want to be use my code in centralised way like for new target, I don't want to copy and paste the Main.storyboard and xib as well, so, ideally what would happen, if I would change anything in one place, all target would share that.But the issue comes, that ``ViewControllerinMain.Storyboard` holds the master project "module" so, when I run the child target, it could not run.

您可以打开实用工具"面板,选择文件"检查器选项卡,然后为您要共享的每个文件标记必要的目标.请参阅附图作为参考.

You can open Utilities panel, select File inspector tab and mark necessary targets for every file you want to share. See attached image as a reference.