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

Viewed 49857

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

I'd like to rename a class.

11 Answers

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

If you are using Objective-C++ (i.e. mix Objective-C with C++ code) then refactoring is disabled in xcode since it does not support refactoring of C++ code.

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

For me I realized Refactor was disabled because the Xcode project I had opened was referencing a Base SDK that was missing. Edit Project Settings and in the Build tab set the Base SDK to one that you have (like for me this was iOS 4.2). This enabled Refactor for me.

This may be a bit late, but I stumbled across this post because I was unable to refactor my "ViewController.swift" file to "WhateverViewController.swift". I tried selecting the file in the Project Navigator and then selecting "Editor -> Refactor" from the top menu, but 'rename' is always greyed out.

Instead, what worked was selecting the ViewController name from the editor. So if you have:

class ViewController: UIViewController {
 // Code here...
}

Highlight the "ViewController" word and then select Refactor from the menu or right-click and select Refactor -> rename.

Hopefully that helps...

Related