AppCode
 
Get AppCode

Extract function

Last modified: 28 March 2023

Language: Swift, Objective-C

Shortcut: Ctrl+Alt+M

The Extract Function refactoring lets you take a code fragment that can be grouped together, move it into a separated function and replace the old code with the function call.

The Extract Function refactoring has the following limitations:

  • Refactoring does not work with multiple output values in the automatic mode. You have to change your code before applying the refactoring, for example, you may introduce a special data-class that contains all output values.

  • Refactoring does not work for a code fragment which conditionally returns from the containing method and is not placed at the end of it.

https://resources.jetbrains.com/help/img/idea/2023.1/ac_extract_method.png
Gif

To reverse the Extract Function refactoring, press Ctrl+Alt+N to invoke the Inline refactoring.