Rename failed in Xcode 9

zephyr picture zephyr · Sep 27, 2017 · Viewed 20.7k times · Source

I used "renamed" function to rename a variable named "DefaultRequestURL" in Xcode 9, it alert this: alert image I have checked the file "ComposeController.swift", there is no "DefaultRequestURL"。 I have restart Xcode and do "Product -> Clean", it still failed.

why this? What should I do?

Answer

Vlad E. Borovtsov picture Vlad E. Borovtsov · Oct 6, 2017

Try again in few minutes. Maybe background indexing still running. Also, you must build your project in order to be able to use refactor->rename. Actually, it must be a bug in Xcode 9. Try 9.1 beta, refactor is not ideal, but works better there. this maybe helpful: https://forums.developer.apple.com/thread/80331

UPDATE:

  1. Close Xcode
  2. Go to ~/Library/Developer/Xcode/DerivedData and remove folder contents including "ModuleCache".
  3. Open your project and build
  4. Try rename functionality now. It should work!

Update 2:

For Xcode 10, it's enough just to restart it.

Update 3:

Still works for Xcode 12. Sometimes just restart helps, sometimes module cache needs to be removed. Sometimes even build->clean helps.