> For the complete documentation index, see [llms.txt](https://gitbook.existorlive.cn/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://gitbook.existorlive.cn/kai-fa-yu-yan-xue-xi/swift/7.-bi-bao/3.-wei-sui-bi-bao.md).

# 尾随闭包

如果你需要将一个很长的闭包表达式作为**最后一个参数传递给函数**，将这个闭包替换成为尾随闭包的形式很有用。

> 只有闭包表达式作为函数的最后一个参数，才可以写为尾随的形式。

```swift

// 未使用尾随闭包
reversedNames = names.sorted(by: { s1, s2 in
    s1 > s2
})

// 使用尾随闭包，参略(),参数标签
reversedNames = names.sorted { s1, s2 in
    s1 > s2
}

```
