Question

On both Xcode 4.4 and 4.4.1 I'm experiencing the same issue in that with the specific project I'm working on, I don't seem to be able to rename any classes or variables from the Refactor menu option.

Each time I try and do a rename, I type in the new name for the class/variable and click Preview at which point the bottom left begins a spinner with Finding files.... However, I then get a message saying:

The selection is not a type that can be renamed.

Make a different selection and try again.

I'm pretty sure that this is not an issue with my specific install of Xcode, because I can refactor other projects fine, it's just that I can't seem to be able to refactor this specific project.

Anyone with any ideas? I don't have any particularly exotic configuration for this project, it just seems to be a random affliction. I've deleted all of my derived data and re-indexed, but that doesn't seem to help.

Since it works OK in other projects, I'm thinking one thing I could try to do is re-generate the actual project file(s) itself. I don't know if there is a way to do this automatically?

Was it helpful?

Solution 2

I have managed to solve this issue after trying many different things (tweaking project settings, pch, etc.) and it turns out there was a very simple (and totally counter-intuitive) method of fixing this issue.

All I have done is:-

  1. Copy my entire project folder (so from Project to Project Copy).
  2. Move Project (the original folder) to trash.
  3. Rename Project Copy to Project.

Mysteriously, everything now works fine.

I really cannot figure out why this works. As mentioned previously, I had already deleted all derived data, etc. so I don't know why this should make things spontaneously work, but it does.

Would appreciate anyone who is able to shed some light on this as it does expose just how fiddly Xcode can be, and any understanding of what goes on under the hood is always beneficial.

OTHER TIPS

If they're in dropbox get them out of there. It mangles project files. I've had it happen numerous times and at times it makes refactoring > renaming not work.

Sounds like a buggered index.

I usually use the nuke from space option to delete everything in the derived data directory.

Unless you have changed it (I change mine to /tmp/bbum-derived), it'll be at:

~/Library/Developer/Xcode/DerivedData

Thus, I'll quit Xcode and do:

rm -rf ~/Library/Developer/Xcode/DerivedData

Yes, it is a bit brute force, but it works. You can likely force Xcode to rebuild the index from the UI, but I never bother. Of course, I'm also installing quite a few "odd" builds of this and that as a part of my day job...

(that is an rm -rf. It means "nuke everything and don't ask" in unix parlance. It is dangerous. Do not mistype that command.)

It seems you have an active selection somewhere in the gui, perhaps some of your files or classes are selected ? Try unselect in every sub window and retry refactoring.

I'm a bit late to this thread, but I ran into the same problem today and I was able to get it to finally refactor correctly, thought I share it.

So in large part I did what bbum said, I closed xCode, nuked the Derived data for the project the class files were in and re opened the project. Doing just that, it didn't work; the key, I found (at least for me), is that I had to do a clean (command shift k) after xCode restarts. After that I was able to rename the class files again :)

Also as a side note, my project is divided into the main project, and a static library. When I had to rename classes in the static library, I had to quit the main project and do what I described in the static library itself. Somehow I got the same error described in the question when I tried to do the refactor/rename from the main project.

Good luck!

This thread was very helpful for me in determining the problem.

It turned out that I had to Repair Disk with Disk Utility. I had visited a site earlier that had hijacked Safari and was telling me to call a number for emergency repairs, an obvious scam.

I followed the Disk Utility instructions to repair disk (including restarting with CMD-R pressed). Another clue was that I tried to commit to git and Xcode said No Way, Jose.

Afterwards I was able to refactor and commit changes as if nothing ever happened. I hope this helps someone else as a possible cause to investigate.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top