有没有办法简化 Swift 尾随闭包的输入?

有没有办法简化 Swift 尾随闭包的输入?

问题描述:

尾随闭包使代码更具可读性,但编码过程一点也不愉快.例如,当我想输入这种只接受一个闭包参数的方法(如下所示)时.没有选择尾随闭包的代码提示:

Trailing closure make code more readable, but the coding process is not enjoyable at all. For example, when I want to type this kind of method (shown below) that only takes one closure parameter. There is no Code hint for choosing trailing closure:

我必须删除()里面的内容,然后输入完整的闭包:

I have to delete content inside(), and type the complete closure like that :

有没有办法让这更容易?

Is there a way to make this easier?

输入 ENTER 两次,一次完成方法名称,第二次自动格式化闭包.

Type ENTER twice, once to complete the method name, a second time to automatically format the closure.

当我开始输入函数名时:

When I begin to type the function name:

按一次 ENTER 后:

然后,在第二次按下 ENTER 后:

Then, after hitting ENTER a second time:

总结:输入函数的第一个字母,等待自动建议,然后按 ENTER 再按 ENTER.

To sum up: type the first letters of the function, wait for auto-suggest, then hit ENTER then ENTER again.