如何在 Xcode 5中重命名项目?

如何在 Xcode 5中重命名项目? 我需要采取什么步骤? 在过去,这总是一个非常棘手的手工过程。

63893 次浏览

Well, the answer is very very very Apple simple in Xcode 5! In the Project Navigator on the left side, click 2 x slowly and the Project file name will be editable. Type the new name. A sheet will appear with a warning and will list all the items Xcode 5 believes it should change. You can probably trust it, but you should inspect it. The list will include the info.plist and various files, but also all the relevant strings from nib/xib files like MainMenu menus.

Accept the changes and you will get the prompt to save a snapshot of the project. Always make a snapshot when Xcode asks, it will be useful to restore if something does not work.

Here is another great example which works well with xcode 5

Change the project name:-

  1. Click on the target in xcode, on the right in "Identify and Type" under name change the name and press the ENTER button on your keyboard.
  2. A window will appear confirming the change and what it will change. Once you confirm it will make the changes.

Change the root folder name:-

  1. Go to the project directory and rename the root folder,
  2. Open the project and u will find all the file are missing, u need to add all the files of project again
  3. Right click the project bundle .xcodeproj file and select “Show Package Contents” from the context menu. Open the .pbxproj file with any text editor. 4>Search and replace any occurrence of the original folder name with the new folder name. 5>Save the file.

Change the Scheme name:-

  1. rename .xscheme file enter image description here

If your Project is static framework then make sure your header file has public target membership

When you re-name the project name in XCode5 then info.plist entry removed from Targets --- > General ---> identity. You just need to mention it again.

enter image description here

I really recommend just opening the folder in a general editor such as Sublime Text, and doing a find/replace across the whole folder. The other methods I found were unstable, particularly when combined with .xcworkspace and cocoapods.

Xcode 6 (beta 6 as of now) seems to be not very reliable with renaming projects. For me it didn't rename several of the files and groups. It also doesn't rename the physical folder the project is in. To rename my project to be sure that everything is clean I went the extra length to create a new project with the new name and copy over all the files. The assets are easy to copy but groups have to be recreated. The biggest issue with this however are CoreData data model files. Trying to simply copy this will result in a corrupt model file, even though everything looks like it is alright.

In Xcode 7, renaming a project can still break your app. Make sure you backed it up before trying it. Click on the project icon and find the project name in the inspector pane. If you change it there, Xcode will ask you if you want to rename related files. Might work. But if not, try this brute force approach:

  1. Close Xcode
  2. Using an advanced text editor like Sublime Text or Atom, open the root folder. It will open the folder structure.
  3. Perform a Global Search and Replace (it's probably cmd + shift + f), and replace My Wrong App Name with New App. If your project name contained spaces, also search for My_Wrong_App_Name and replace with New_App. This changes all file contents.
  4. Now you need to find all the files inside the project with your old app name. Rename them all, also the folders.
  5. Important: Open the project file with right click > Show Package Contents, and rename all files in there.
  6. Reopen your Xcode project or workspace. Compile.

If you use Pods, you need to open the pods project as well and change the files in there.

In Xcode 8.0, to rename your project, just go through the following instructions as described in Xcode help:

1- Select your project in the project navigator.

2- In the Identity and Type section of the File inspector, enter a new name into the Name field.

3- Press Return.

A dialog is displayed, listing the items in your project that can be renamed. The dialog includes a preview of how the items will appear after the change.

4- To selectively rename items, disable the checkboxes for any items you don’t want to rename. To rename only your app, leave the app selected and deselect all other items.

5- Click Rename.

Source: http://help.apple.com/xcode/mac/8.0/#/dev3db3afe4f