我希望能够复制一个完整的Xcode项目,重命名项目和相关的文件没有Xcode的精神,而不必手动重新导入所有文件到项目。


当前回答

这个答案是互联网上其他各种StackOverflow帖子和教程的集大成之处,供我将来参考,并帮助其他可能面临同样问题的人。所有的分数都给最后的其他答案。

复制一个Xcode项目

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. 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. In Xcode, rename the schemes in "Manage Schemes", also rename any targets you may have. 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中最清晰的文件结构,等等。要重命名此文件夹而不破坏所有文件链接,请执行以下步骤:

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. Note: You may have to do Step 2 first, then come back to this step. 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. 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.

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. 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文件,并冒着把事情搞砸的风险。

学分

非常感谢Nick Lockwood和Pauly Glott为这个问题提供了不同的答案。

复制一个Xcode 4项目 重命名xcode 4项目和实际文件夹

其他回答

在“即时OpenCV for iOS”一书的示例代码中,我发现了一个bash脚本,可以将项目从一个文件夹复制到另一个文件夹。 做了一些研究,我发现了一篇似乎是脚本原作者的博客文章:http://mohrt.blogspot.it/2009/01/renaming-xcode-project-from-command.html,在那里你可以下载脚本。我试了一下,像这样从终端运行它

    sh renameXcodeProject.sh <name-of-existing-folder> <name-of-folder-to-create>   

工作很好。 其他信息可以用文本编辑器打开文件。希望这能有所帮助

我使用简单的BASH脚本重命名。

使用方法:./rename.sh oldName newName

#!/bin/sh

OLDNAME=$1
NEWNAME=$2

export LC_CTYPE=C 
export LANG=C
find . -type f ! -path ".*/.*" -exec sed -i '' -e "s/${OLDNAME}/${NEWNAME}/g" {} +

mv "${OLDNAME}.xcodeproj" "${NEWNAME}.xcodeproj"
mv "${OLDNAME}" "${NEWNAME}"

注:

这个脚本将忽略所有像.git和.DS_Store这样的文件 如果旧名称/新名称包含空格,将无法工作 如果使用豆荚可能无法工作(未测试) 方案名称不会更改(无论如何项目正常运行和编译)

这个答案是互联网上其他各种StackOverflow帖子和教程的集大成之处,供我将来参考,并帮助其他可能面临同样问题的人。所有的分数都给最后的其他答案。

复制一个Xcode项目

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. 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. In Xcode, rename the schemes in "Manage Schemes", also rename any targets you may have. 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中最清晰的文件结构,等等。要重命名此文件夹而不破坏所有文件链接,请执行以下步骤:

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. Note: You may have to do Step 2 first, then come back to this step. 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. 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.

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. 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文件,并冒着把事情搞砸的风险。

学分

非常感谢Nick Lockwood和Pauly Glott为这个问题提供了不同的答案。

复制一个Xcode 4项目 重命名xcode 4项目和实际文件夹

我之所以发布这篇文章,是因为在XCode中重命名一个项目时,我一直很纠结。

重命名项目很好,也很简单,但这并没有重命名源文件夹。下面是我在Xcode 4和5中所做的一步一步的工作,感谢下面的链接。

参考链接: 重命名项目。 重命名源文件夹和其他文件。

备份你的项目。

如果你正在使用git,提交任何更改,在进行任何更改之前复制整个项目文件夹并在时光机中备份(这一步不是必需的,但我强烈推荐)。

2-打开你的项目。

3-缓慢双击或按enter项目名称(蓝色顶部图标),重命名为任何你喜欢的。

注意:重命名项目并按“enter”后,它会提示自动更改所有与项目名称相关的条目和 如果你愿意,可以取消选择其中的一些。选择所有 然后单击ok。

4-重命名方案

a)点击停止按钮旁边的菜单,选择“管理方案”。

b)在旧的名称方案上单次慢点或按enter键,并将其重命名为任何你喜欢的名称。

c)单击“确定”。

5 -构建并运行以确保它工作正常。

注意:在这一点上,除了在项目创建时创建的类中的注释之外,所有重要的项目文件都应该重命名 也没有创建源文件夹。接下来,我们将重命名文件夹 文件系统。

6-关闭项目。

重命名主文件夹和源文件夹。

8-右键单击项目包。xcodeproj文件,并从上下文菜单中选择“显示包内容”。用任何文本编辑器打开.pbxproj文件。

9-搜索并替换任何出现的原始文件夹名称与新的文件夹名称。

10-保存文件。

11-打开XCode项目,测试。

12 -完成。

编辑10/11/19:

在Xcode中有一个重命名项目的工具,我还没试过,就不评论了。 https://github.com/appculture/xcode-project-renamer

我在重命名我的iOS项目后使用这个脚本。它有助于更改目录名称并使名称保持同步。

http://github.com/ytbryan/rename

注意:您需要手动更改方案的名称。