使用 提取闭包 重构 (Swift),您可以基于选定的代码块创建闭包。选择要提取的表达式,然后按 &shortcut:Refactorings.QuickListPopupAction; 并选择 提取闭包:

The Extract Closure refactoring

在打开的对话框中,输入新闭包的名称并根据需要更改参数名称和类型。

此操作将产生以下结果:

The Extract Closure refactoring