'Xcode 11.5 Rename Refactor failed when trying to rename variable

When I try to re-name any variable, Xcode give me the following error:

I have tried restarting Xcode but the same thing happens. Any ideas how to fix?



Solution 1:[1]

I just had this issue with Xcode 11.6 and I solved it like this:

  1. Close Xcode
  2. Delete all contents of the DerivedData folder (located in ~/Library/Developer/Xcode/DerivedData)

And thats it! When I reopened Xcode it let me use the rename feature.

Solution 2:[2]

My experience is that this due to Xcode's (very poor) git integration. When I turn off git integration, the rename works fine.

Solution 3:[3]

For me in general a simple restart (or restart the mac) resolves this problem, but when I use version control (e.g. git + github, azure) sometimes I have to make a commit (and maybe a push) in order to make everything works. After these steps I can always refactor the things.

Solution 4:[4]

A quick and safe solution :

  1. Close Xcode
  2. Open Terminal and execute cd ~/Library/Developer/Xcode/DerivedData which will list all your projects
  3. Execute rm -rf {PROJECT_NAME}-* replace the PROJECT_NAME with the corresponding project that you're working on.
  4. Re-open your application.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 ThiagoAM
Solution 2 matt
Solution 3 Dharman
Solution 4 Dev Agani