Extract closure
Last modified: 14 December 2022Language: Swift
The Extract Closure refactoring creates a closure out of the selected chunk of code.

Gif
Extract a closure
In the editor, select an expression which you want to extract into a closure.
Press Ctrl+Alt+Shift+T and select Extract Closure. Alternatively, select Refactor | Extract/Introduce | Closure from the main or context menu.
If there are several expressions available for extracting, select the required one from the list that opens and press Enter.
In the dialog that opens, type the name of the new closure and change the parameter names and types if necessary.
Press Enter.
Before | After |
---|---|
|
|
Thanks for your feedback!
Was this page helpful?