zephyr
zephyr

Reputation: 1098

Rename failed in Xcode 9

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?

Upvotes: 48

Views: 26635

Answers (4)

void
void

Reputation: 1365

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.

Upvotes: 96

Gary M
Gary M

Reputation: 438

There is no need to remove DerivedData folder & rebuild.

  1. close Xcode
  2. remove DerivedData/ModuleCache.noindex folder
  3. open Xcode
  4. rename/refactor

Working on 10.2.1

Update

Working on Xcode 12 beta 4 but did need to wait for indexing to finish.

Upvotes: 2

Simon Moshenko
Simon Moshenko

Reputation: 2166

For me there was already a folder with the name I tried to rename to for some reason. Manually removing the folder helped.

Upvotes: 1

wlixcc
wlixcc

Reputation: 1492

Thanks for Vlad E. Borovtsov, It's help me to resolve problem and I fonud there is a way not close xcode. This is my way to fix it:

  1. Go to ~/Library/Developer/Xcode/ , remove DerivedData folder

  2. command+r to run ,or command+b to build

  3. Try rename , it work for me .

xocde reindex and rename can work

Upvotes: 25

Related Questions