Xcode 4.4 unable to rename classes/variables
Asked Answered
O

6

7

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?

Ontology answered 10/8, 2012 at 14:8 Comment(2)
Xcode refactor option is crap, however it is supposed to work decently for Obj-C. Is your class plain Obj-C (and not Obj-C++ or C++) ?Unmoral
Slightly tangentially, you might want to give JetBrains' AppCode a try. Its refactoring support is far superior to that of Xcode.Polypary
O
4

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.

Ontology answered 20/8, 2012 at 11:18 Comment(4)
This issue has now been fixed in the latest version(s) of Xcode.Ontology
Which version? I've just installed version 4.5.1 (4G1004) and it still exhibits the same problem.Kamerad
It's absurd, but it worked for me too in Xcode 5.0.1 @philosopherdog below mentioned that keeping projects on dropbox can cause problems - mine is, was yours?Masterstroke
Didn't help, XC 6.2, os 10.9Pineal
P
6

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.

Peep answered 29/9, 2013 at 21:15 Comment(7)
Is this a bug on Apple's part of Dropbox's? Either way, F the suggestion of simply not using one or the other.Aceldama
All I know is dropbox is a bad place to store active project files. Eventually they bork. That's been my experience, and others report this too.Peep
This is a good answer @philosopherdog. Putting it in a dropbox from Mac A and accessing it by Mac B would really cause Mac B to not be able to do renaming. This is because the snapshot is not activated by Mac B. You can fix this issue and still continue using dropbox by (1.) Simply transferring the project to a different folder outside of dropbox. (2.) Open the transferred project using Xcode. (3.) Perform refactoring to trigger the snapshot feature. (4.) Close Xcode (5.) Transfer the copied project back to dropbox (6.) Enjoy refactoring on Mac A and Mac B while still using dropbox.Gerdi
@Gerdi I keep projects in Dropbox that I'm not ACTIVELY DEVELOPING. I've found if you're ACTIVELY working on an app and you store it in Dropbox, eventually there are glitches. Many people report this. It makes sense. Dropbox is good, but there are too many ways things can go wrong when saving every few minutes over the wire. I have moved all active projects to a proper git repo like BitBucket or Github. I had the very problem posted here by the OP and it was caused by having my project in Dropbox. Moving it out, solved the issue.Peep
I moved my active project out of Dropbox and now refactoring works again.Artichoke
Worked for me. I still wanted my project to be synced to Dropbox so I used a symlink pointing from my project folder outside of Dropbox into my Dropbox folder. Here's how: dropboxwiki.com/tips-and-tricks/sync-other-foldersWellbeing
@TygerWhite I tried symlinks with dropbox and it didn't work for me. The key I think is if you have two devices accessing the store at the same time this is where you run into trouble with Dropbox. If you're really careful and make sure everything is synced before accessing from another device you can avoid problems. Personally, I have found I'm way better off using Bitbucket. It's free for private repos and isn't going to mangle your files.Peep
O
4

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.

Ontology answered 20/8, 2012 at 11:18 Comment(4)
This issue has now been fixed in the latest version(s) of Xcode.Ontology
Which version? I've just installed version 4.5.1 (4G1004) and it still exhibits the same problem.Kamerad
It's absurd, but it worked for me too in Xcode 5.0.1 @philosopherdog below mentioned that keeping projects on dropbox can cause problems - mine is, was yours?Masterstroke
Didn't help, XC 6.2, os 10.9Pineal
B
2

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.)

Barleycorn answered 10/8, 2012 at 14:20 Comment(1)
Nope -- this hasn't fixed it! (I did already delete the DerivedData using Finder.) I have now tried rm -rfing it as per your instructions, but after rebuilding the index I just still get the same issue.Ontology
P
0

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.

Patriapatriarch answered 10/8, 2012 at 14:20 Comment(6)
I have checked this, nothing else is selected. It also works fine in other projects with -- from what I can see -- an identical setup.Ontology
Mhm, then what is the type (interface, class ...) of the target for your refactoring ? Does the refactor popup name that target properly ?Patriapatriarch
It doesn't matter what I try to rename, whether it's an interface, implementation, local variable, method name, etc. But yes, the name does come up correctly in the refactor popup. It's only when I go to Preview that it fails...Ontology
I have had to resort to the Replace option in the search navigator view a number of times. Seems one might get oneself a "bad project", especially if you fiddle with the file-type and use Objective-C++ somewhere.Patriapatriarch
I don't use Objective-C++ or file type anywhere. This is a pretty simple and straightforward project which is why I can't figure out why this issue is affecting only this specific project. I'm wondering whether there is some way to sanitise or rebuild the project metadata. (Obviously tried derived data).Ontology
If you can, please zip up the project and file a bug with the project attached and an explanation. (Or send it to me -- bbum @ apple... and I'll file the bug). Something is whack; I suspect the PCH.Barleycorn
Q
0

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!

Quadric answered 19/6, 2013 at 0:6 Comment(0)
C
0

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.

Corfu answered 23/8, 2015 at 21:55 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.