AppCode 2016.2 Help

Extract Method

Basics

When the Extract Method refactoring is invoked , AppCode analyses the selected block of code and detects variables that are the input for the selected code fragment and the variables that are output for it.

The detected output variable is used as a return value for the extracted function.

Examples

JavaScript example

BeforeAfter
function multiplication(a,b) { c = a + b; d = c * c; return d; }
function sum(a,b); return a + b; function multiplication(a,b) { c = sum(a,b); d = c * c; return d; }

Extracting a method

To extract a method, follow these steps

  1. In the editor, select a block of code to be transformed into a method or a function.
  2. On the main menu or on the context menu of the selection, choose Refactor | Extract | Method or press ⌥⌘M.
  3. In the Extract Method dialog box that opens, specify the name of the new function.
  4. Specify method parameters.
  5. In the Targets selector, choose where the method should be declared - in the header file, in a private category, or in the implementation file.
  6. Check the result in the Signature Preview pane and click OK to create the required function.

    The selected code fragment will be replaced with a function call.

    AppCode_ExtractMethodRef

See Also

Last modified: 20 July 2016