Figure 2-1 illustrates the refactoring workflow in Xcode.
These are the steps of a refactoring:
Select the code to transform, which identifies the transformation item.
The selected code can be located in any source file that’s part of the current project. The selected codelines, including code fragments, always identify only one transformation item. The transformation item is either the name of a symbol or a code fragment:
Symbol name. The transformation affects the header and implementation files that declare and define the item, and other files that directly access the item, including nib and Core Data–model files.
Code fragment. The transformation affects the scope containing the codelines (within a single file).
Choose a transformation.
For transformations that operate on a single transformation item, choose Edit > Refactor.
and choose a transformation from the transformation pop-up menu in the Refactoring window.
Define the transformation.
You define the transformation in the Refactoring window, which contains:
The transformation menu
Transformation specifiers (vary according to the transformation)
Transformation options (vary according to the transformation)
Transformation editor pane
Preview/modify the transformation.
In the transformation editor you can choose which changes to include in the transformation. Xcode selects all changes it deems necessary for the transformation.
Apply the transformation.
To ensure that you can revert the transformation if it doesn’t prove beneficial, make sure the Snapshot option is selected before clicking Apply.
Compile the source code.
Some transformations require that you perform additional work outside the transformation editor to complete them. You can use compilation errors and warning to determine the fixes you need to make.
Test the code.
If you created unit tests for the code involved in the transformation, run them to ensure the transformed code behaves as expected.
If there are problems, you can revert the transformation in the Snapshots window (if the Snapshot option was selected when you applied the transformation).
© 2009 Apple Inc. All Rights Reserved. (Last updated: 2009-01-06)