7

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?

Pranav Kasetti
  • 8,770
  • 2
  • 50
  • 71

5 Answers5

10

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.

ThiagoAM
  • 1,432
  • 13
  • 20
  • 1
    I wouldn't call it a that's-it, haha. After you clean derived data, you need to re-build the project (for big projects it may take 5min or even more) and resolve Swift packages if any (I have three of them, including Firebase, and it takes another 5-10min). Quite a price for such a basic action as variable renaming! – lazarevzubov Oct 29 '21 at 08:08
1

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

matt
  • 515,959
  • 87
  • 875
  • 1,141
0

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.

Dharman
  • 30,962
  • 25
  • 85
  • 135
jason d
  • 416
  • 1
  • 5
  • 10
  • 1
    Thank you for your answer, I have tried restarting XCode, the mac and committing and pushing but none of them work, I am still getting the same error. – Carlos Rosety Jul 29 '20 at 12:39
0

I still see this on Xcode14. I suspect this over-simple message can have all sorts of causes. If you are having trouble, try working like this...

Build (and check it builds) Refactor Build (and check it still builds)

The refactoring should work on valid code. In my case, I was replacing a 'customWhite' with 'tint'. I don't use 'tint' in the application, but something else did, giving me a type mismatch. This type mismatch then made the next refactor fail in the usual way.

Richard Kirk
  • 281
  • 1
  • 12
-2

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.
Dev Agani
  • 1
  • 1