Can't Rename Files In Xcode 4 Anymore?

2020-08-11 00:32发布

问题:

Seriously, in previous versions of XCode I could right-click a file or group in XCode and I would get the "rename" option. In XCode 4 I can't seem to rename my files in XCode directly anymore. What happened? Why would Apple remove such a feature? How can I rename my nibs, image resources, and others in XCode now?

回答1:

The contextual menu item was removed, but you can still rename from within. Select the file and then click again in the name and you should get the editor field. Type away to rename. It can be a little temperamental though. The biggest problem I usually have is doing the 2nd click too quickly and it being registered as a double click. So you might need to play around with your timing a little bit to get used to it.

If you want the CM item back, make sure to file a bug report on it.



回答2:

Note that if you're renaming a class, the best way I've found to do this is to open the class header, select the name of the class then control-click and choose Refactor / Rename. That way Xcode will rename the .h and .m files and replace instances of your class name (almost) everywhere it appears, including XIB files. Nifty!


Edit: in Xcode 4.2, watch out for this gotcha: "When initiating a refactoring rename operation from the declaration of a property, any Interface Builder files that refer to that property will not be updated correctly. Instead, perform the rename operation on a usage of the property, or an associated @synthesize statement."



回答3:

Select the file in the navigation window and press Enter. Just the way renaming in Finder.



回答4:

In case you want to change the path in case you moved some files...

Step 1: View -> Utilities -> File Inspector to open the file inspector Step 2: Under Identity -> Path there is a white icon to change the relative path of the file

Furthermore, to rename the file, just refactor as stated above ;)



回答5:

another way you can do it, is by using the little rectangle with an arrow in it which is at the bottom of the bar. Click on it, your items will be displayed in a list like view, you can rename it there the way you would rename files or whatever... Hope that helps



回答6:

If you want to rename non-class files like png files just select file and choose 'Show File Inspector' from right click, then change file name from 'name' textfield (identify and type label).

I you want change class name, I recommend 'Simon Whitaker' Refactor method (second comment).



标签: xcode4