Rename failed in Xcode 9
Asked Answered
K

4

48

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?

Kornegay answered 27/9, 2017 at 9:37 Comment(0)
P
96

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.

Presbyterate answered 6/10, 2017 at 14:6 Comment(8)
Do you mean deleting the entire content of DerivedData folder??? There's tons of stuff there. Are you saying we don't need none of them???Skyline
@Skyline it's kind of temporary files/cache. It's safe to delete them all. Xocde stores indexes, object files, some prebuilt stuff there, swift module cache, etc. Those contents will show up again once you build your project again.Presbyterate
This did not work for me as of Xcode 9.3, April 2018.Antecede
@JamesShapiro try to reboot your machine. Or open activity monitor and look for "SourceKit" process, if it's there - kill it. Sometimes it hangs and wont quit along with Xcode.Presbyterate
I just had the same problem with Xcode 10.1. In a Swift enum, I could rename 2 of 4 cases, and the other 2 just gave me an error message. (They were all normal identifiers, no 'default' or something else that would have to be put into quotes.) Restarting did not work. Closing Xcode, deleting the DerivedData folder did work, then restarting Xcode did work however. - I didn't wait until indexing is done, as it was not necessary. When you try to refactor and indexing is not completed yet, it will just take longer because it has to do the indexing first.Xylon
Using Xcode 10.1: I had to Quit Xcode, remove the project and "ModuleCache.noindex" directories under DerivedData, then launch Xcode and refactor.Integumentary
Using Xcode 10.2.1: just close and open didn't do the job for me. Deleting the folder DerivedData did.Stambul
Solution is still just deleting ''ModuleCache"Felike
N
25

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

Neurocoele answered 21/11, 2017 at 9:40 Comment(4)
eheh, yeah it should work. But really it's always good to close Xcode and launch again when you have a chance. Relaunch always makes it run a little faster, especially if you have a deal with storyboards.Presbyterate
@JamesShapiro sorry about that, I only try this for Xcode9.1Neurocoele
I am using Xcode 10.0 and issue still persists in version of XCode, is it resolved in Xcode 11?Alcestis
Getting it in 11.3.1. Cleaned build directory from within Xcode, quit Xcode, removed the DerivedData and started Xcode but still couldn't rename. Had to rename in Finder and readd the files within Xcode.Giraffe
M
2

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.

Mita answered 8/6, 2019 at 5:47 Comment(2)
It also happening on 11.3.1. And the approach still works!Presbyterate
It is happening in 11.6. Cleaning, restarting Xcode don't work. I'll try these steps. Edit: this did not work.Jecon
R
1

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

Roundhouse answered 3/8, 2020 at 13:19 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.