# 版本兼容性

{% hint style="info" %}
最新的 Swift 6 版本的文档已发布，可前往 [doc.swiftgg.team](https://doc.swiftgg.team/documentation/the-swift-programming-language/) 查看
{% endhint %}

本书描述的是在 Xcode 14 中默认包含的 Swift 5.7 版本。你可以使用 Xcode 14 来构建 Swift 5.7、Swift 4.2 或 Swift 4 写的项目。

使用 Xcode 14 构建 Swift 4 和 Swift 4.2 代码时，Swift 5.7 的大多数功能都适用。但以下功能仅支持 Swift 5.7 或更高版本:

* 返回值是不透明类型的函数依赖 Swift 5.1 运行时。
* **try?** 表达式不会为已返回可选类型的代码引入额外的可选类型层级。
* 大数字的整型字面量初始化代码的类型将会被正确推导，例如 **UInt64(0xffff\_ffff\_ffff\_ffff)** 将会被推导为整型类型而非溢出。

并发特性需要 Swift 5.7 及以上版本，以及一个提供了并发相关类型的 Swift 标准库版本。要应用于苹果平台，请至少将部署版本设置为 iOS 15、macOS 12、tvOS 15 或 watchOS 8.0。

用 Swift 5.7 写的项目可以依赖用 Swift 4.2 或 Swift 4 写的项目，反之亦然。这意味着，如果你将一个大的项目分解成多个框架（framework），你可以逐个地将框架从 Swift 4 代码迁移到 Swift 5.7。


---

# Agent Instructions: 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.swiftgg.team/swift/huan-ying-shi-yong-swift/02_version_compatibility.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.
