Information Technology Reference
In-Depth Information
Create new superclasses
Move code into a superclass
Move code into a subclass
Create new setters and getters for a symbol
Refactoring can seem mysterious because the options that appear in the Refactor menu are context- and
selection-dependent. Xcode displays only the options that make sense; for example, you can't create a super-
class for a property.
NOTE
Xcode's refactoring features are based on ideas introduced by developer Martin Fowler. For more information, see
http://martinfowler.com . Refactoring has been hotly debated, but you don't need to be familiar with the debate to
use the Refactor menu to work with your code.
CAUTION
Refactoring can make drastic, wide-ranging changes to a project. It's a good idea to back up a project using one of
the options introduced in Chapter 14 before you use this feature. Note that some refactoring options, such as re-
name, can be very slow.
Refactoring typically works in two stages. First you select an operation and type a parameter, such as a new
name, into a dialog. Next, Xcode displays the preview and confirmation dialog shown in Figure 9.5. The pre-
view shows a list of proposed changes in various files at the left, and before/after views of the code at the right.
Clicking Save actions the changes. You can also deselect one or more of the check boxes at the left to leave those
items unchanged. For some operations, the proposed changes can be complex and may be spread across mul-
tiple sections in multiple files.
The following options are available:
Rename: This works on classes, properties, and method. Select a feature and the Rename option from
the menu. Type a new name into the dialog box. Xcode searches every file in the project—this can take a
while—and shows the preview/confirmation dialog.
Extract: This works on methods or code sections. You can move a section of code into a separate method
or function. Xcode automatically creates a new signature for you. You can edit this before you confirm the
change.
Create Superclass: This works on class names. It creates a new superclass. The definition code can be
written to a new file, which is the most useful option, or it can be added to the current file, which can be
confusing and isn't usually useful. You typically need to fix included/imported headers manually in the su-
perclass definition.
Move Up/Down: This works on methods and properties. Move Up moves the item to the superclass; in
other words, it removes the code from the current file and moves it to the superclass definition file. Move
Down moves it from the superclass to a subclass.
Search WWH ::




Custom Search