复制并重命名 Xcode 项目 &关联文件夹 [英] Duplicate and rename Xcode project & associated folders

查看:47
本文介绍了复制并重命名 Xcode 项目 &关联文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望能够复制整个 Xcode 项目、重命名项目和相关文件,而无需 Xcode 思考,也无需手动将所有文件重新导入项目.

I would like to be able to duplicate an entire Xcode project, rename the project and the associated files without Xcode going mental, and without having to manually re-import all files to the project.

推荐答案

这个答案是互联网上各种其他 StackOverflow 帖子和教程的高潮,汇集到一个地方供我将来参考,并帮助任何可能面临同样的问题.所有的功劳都在最后给出了其他答案.

This answer is the culmination of various other StackOverflow posts and tutorials around the internet brought into one place for my future reference, and to help anyone else who may be facing the same issue. All credit is given for other answers at the end.

  • 在 Finder 中,将项目文件夹复制到新项目的所需位置.在此阶段不要重命名 .xcodeproj 文件名或任何关联的文件夹.

  • In the Finder, duplicate the project folder to the desired location of your new project. Do not rename the .xcodeproj file name or any associated folders at this stage.

在 Xcode 中,重命名项目.从导航器窗格(左窗格)中选择您的项目.在实用程序窗格(右窗格)中重命名您的项目,接受 Xcode 建议的更改.

In Xcode, rename the project. Select your project from the navigator pane (left pane). In the Utilities pane (right pane) rename your project, Accept the changes Xcode proposes.

在 Xcode 中,重命名管理方案"中的方案,同时重命名您可能拥有的任何目标.

In Xcode, rename the schemes in "Manage Schemes", also rename any targets you may have.

如果您没有使用最后包含当前 PRODUCT_NAME 的默认捆绑标识符(因此会自动更新),请将捆绑标识符更改为您将用于重复项目的新捆绑标识符.

If you're not using the default Bundle Identifier which contains the current PRODUCT_NAME at the end (so will update automatically), then change your Bundle Identifier to the new one you will be using for your duplicated project.

因此,在执行上述步骤后,您应该有一个复制并重命名的 Xcode 项目,该项目应该可以成功构建和编译,但是您的源代码文件夹仍将命名为原始项目中的名称.这不会导致任何编译器问题,但它不是人们在 SCM 等中导航的最清晰的文件结构.要在不破坏所有文件链接的情况下重命名此文件夹,请执行以下步骤:

So after following the above steps you should have a duplicated and renamed Xcode project that should build and compile successfully, however your source code folder will still be named as it was in the original project. This doesn't cause any compiler issues, but it's not the clearest file structure for people to navigate in SCM, etc. To rename this folder without breaking all your file links, follow these steps:

  • 在 Finder 中,重命名源文件夹.这会破坏您的项目,因为 Xcode 不会自动检测更改.您所有的 xcode 文件列表都将失去与实际文件的链接,因此都会变成红色.

  • In the Finder, rename the source folder. This will break your project, because Xcode won't automatically detect the changes. All of your xcode file listings will lose their links with the actual files, so will all turn red.

在 Xcode 中,单击您重命名的虚拟文件夹(这可能就在顶部,就在您实际的 .xcodeproject 下)重命名它以匹配 Finder 中的名称,这不会解决任何问题并且严格来说不是必需的步骤,但让文件名匹配很好.

In Xcode, click on the virtual folder which you renamed (This will likely be right at the top, just under your actual .xcodeproject) Rename this to match the name in the Finder, this won't fix anything and strictly isn't a required step but it's nice to have the file names matching.

在 Xcode 中,在导航窗格中选择您刚刚重命名的文件夹.然后在实用工具"窗格(最右侧)中,单击位置"下拉菜单下方看起来像深灰色文件夹的图标.从这里,导航到查找器中重命名的文件夹,然后单击选择".这将自动重新关联您的所有文件,并且它们在 Xcode 导航窗格中不应再显示为红色.

In Xcode, Select the folder you just renamed in the navigation pane. Then in the Utilities pane (far right) click the icon that looks like dark grey folder, just underneath the 'Location' drop down menu. From here, navigate to your renamed folder in the finder and click 'Choose'. This will automagically re-associate all your files, and they should no longer appear red within the Xcode navigation pane.

  • 在您的项目/目标构建设置中,搜索旧文件夹名称并手动重命名您找到的任何匹配项.通常有一个用于 prefix.pch 和一个用于 info.plist,但可能还有更多.

  • In your project / targets build settings, search for the old folder name and manually rename any occurrences you find. Normally there is one for the prefix.pch and one for the info.plist, but there may be more.

如果您使用任何第三方库(Testflight/Hockeyapp/等),您还需要搜索库搜索路径"并在此处重命名任何出现的旧文件名.

If you are using any third party libraries (Testflight/Hockeyapp/etc) you will also need to search for 'Library Search Paths' and rename any occurrences of the old file name here too.

对您的项目可能包含的任何单元测试源代码文件夹重复此过程,过程是相同的.

Repeat this process for any unit test source code folders your project may contain, the process is identical.

这应该允许您复制 &重命名 xcode 项目和所有关联的文件,而无需手动编辑任何 xcode 文件,否则可能会搞砸.

This should allow you to duplicate & rename an xcode project and all associated files without having to manually edit any xcode files, and risk messing things up.

非常感谢 Nick LockwoodPauly Glott 为这个问题提供了单独的答案.

Many thanks is given to Nick Lockwood, and Pauly Glott for providing the separate answers to this problem.

这篇关于复制并重命名 Xcode 项目 &关联文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆