> 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
}

```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://gitbook.existorlive.cn/kai-fa-yu-yan-xue-xi/swift/7.-bi-bao/3.-wei-sui-bi-bao.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
