Rename a class in Xcode: Refactor… is grayed out (disabled). Why?

后端 未结 10 1444
清歌不尽
清歌不尽 2020-12-13 23:00

Why is Refactor... grayed out (disabled) in Xcode?

I\'d like to rename a class.

相关标签:
10条回答
  • 2020-12-13 23:17

    I'm going to my project at finder, then change files name by get info.

    After that, at xcode -> Project Navigator I delete the files.

    At end, I click right on the class and Add files to ..., and add these files again.

    It worked for me.

    0 讨论(0)
  • 2020-12-13 23:19

    Had this problem as well. I ran through trying to find missing SDKs, saving files, and looking for Objective-C++ code as mentioned above, and all it took to fix my machine was rebooting XCode.

    Seems a little buggy still.

    BTW, this was for XCode 4.0.1

    0 讨论(0)
  • 2020-12-13 23:20

    Select the class's symbol in its header file - i.e. the bit just after @interface. Then the refactoring stuff should be enabled.

    0 讨论(0)
  • 2020-12-13 23:21

    Refactor might also be disabled if affected files (most likely the file with your class in it) are not saved.

    0 讨论(0)
  • 2020-12-13 23:29

    Refactoring works If you first change the file name in the project navigator.

    0 讨论(0)
  • 2020-12-13 23:30

    I've been using Xcode for 5 years now, and refactoring has never worked correctly (even xcode 4.6 has major bugs where it WILL corrupt your source code!).

    The workaround has always been (still works 100%, even in cases where Apple's code fails)

    1. use shift-command-f to find all uses of the file
    2. select "replace" in the search settings
    3. "replace-all"
    4. do the following for the .h file, and REPEAT IT FOR THE .m FILE (if you have one):
      1. right click the original file, and select "show in finder"
      2. delete the file from xcode (select "delete references only" when asked)
    5. rename the .h (and .m if you have one) in Finder
    6. in Xcode, select "Product -> (hold down Alt) -> Clean Build Folder"
    7. quit xcode (you can usually get away with not doing this - but NOTE: there are some other MAJOR bugs in Xcode where it crashes itself if you don't do this)
    8. re-open xcode
    9. drag/drop the .h and .m back into Xcode
    10. wait a few seconds (some of Xcode's core methods are asynchronous - allowing it to corrupt your project)
    11. finally, when it seems to be doing nothing (and your hard disk isn't making any noise any more): cmd-b to re-build

    I have a 100% success rate with this method. I just tried refactoring with Apple's "Refactor -> Rename" in latest xcode and it failed - again!

    (this time with the incorrect error: "Unable to determine the language of", one of those error messages where Apple put the wrong text in place)

    0 讨论(0)
提交回复
热议问题