Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

1304: Update AccessControl.md ⭐️⭐️⭐️⭐️⭐️ #1379

Open
wants to merge 4 commits into
base: swift-6-beta-translation
Choose a base branch
from

Conversation

bh3236
Copy link
Collaborator

@bh3236 bh3236 commented Aug 29, 2024

AccessControl.md 翻译第一稿

AccessControl.md 翻译第一稿
@bh3236 bh3236 linked an issue Aug 29, 2024 that may be closed by this pull request
@yongfrank yongfrank changed the title Update AccessControl.md Update AccessControl.md ⭐️⭐️⭐️⭐️⭐️ Sep 20, 2024
@yongfrank yongfrank changed the title Update AccessControl.md ⭐️⭐️⭐️⭐️⭐️ 1304: Update AccessControl.md ⭐️⭐️⭐️⭐️⭐️ Sep 20, 2024
@pujiaxin33 pujiaxin33 self-requested a review September 24, 2024 02:31

**访问控制**可以限制其它源文件或模块对你的代码的访问。这个特性让你能够隐藏代码的实现细节,并指定一个接口来让别人访问和使用你的代码。

你可以给单个类型(类、结构体和枚举)设置特定的访问级别,也可以给这些类型的属性、方法、初始化器、下标等设置访问级别。协议可以被限制在特定的上下文中,全局常量、变量和函数也可以如此。
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

“初始化器” 建议更新为 “构造器”


Swift 的访问控制模型是基于模块、源文件和包(packages)这三个概念的。

**模块**是代码分发的独立单元——一个框架或应用程序作为一个整体构建和发布,并且可以通过 Swift 的 `import` 关键字被其他模块导入。
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

单元后面的“——”符号建议更改为逗号,


**模块**是代码分发的独立单元——一个框架或应用程序作为一个整体构建和发布,并且可以通过 Swift 的 `import` 关键字被其他模块导入。

在 Swift 中,Xcode 的每个构建目标(例如应用程序或框架)都被视为一个独立的模块。如果你将应用程序中的部分代码打包成一个独立的框架——以便封装这些代码并在多个应用程序中重用,那么当这个框架被导入到某个应用程序或其他框架中使用时,你在框架中定义的所有内容都将属于这个独立的模块。
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

独立的框架后面的“——”符号建议更改为逗号,

using APIs from the [PackageDescription][] module,
and if you use Xcode, you specify the package name
in the Package Access Identifier build setting.
**包**是一组模块的集合,这些模块作为一个整体进行开发。选择哪些模块来构成一个包,是在我们所使用的构建系统中配置的,而不是在 Swift 源代码中。例如,如果使用 Swift Package Manager 构建代码,你会在 `Package.swift` 文件中使用 [PackageDescription][] 模块的 API 来定义包;如果使用 Xcode,你会在“Package Access Identifier”构建设置中指定包名。
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

“Package Access Identifier” 两边加上空格


Swift 为代码中的实体提供了六种不同的**访问级别**。这些访问级别取决于实体所在的源文件、源文件所属的模块,以及模块所属的包。

- *open* 和 *public* 允许实体在同一模块的任意源文件内使用,也可以在导入该模块的其他模块的源文件内使用。通常使用 open 或 public 访问级别来指定框架的公共接口。open 和 public 访问级别的区别将在下文中说明。
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

建议将

openpublic 允许实体在同一模块的任意源文件内使用
翻译为:
openpublic 允许实体被同一模块内的任意源文件使用

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

下面几个前面也都可以使用被动语态优化一下

the original implementation of `someMethod()`:
## 子类

你可以继承同一模块中的所有有访问权限的类,也可以继承不同模块中被 `open` 修饰的类。子类的访问级别不得高于父类的访问级别——例如,你不能写一个 `public` 的子类来继承 `internal` 的父类。
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

不得高于父类的访问级别——
建议后面的——符号修改为句号。

@@ -899,16 +680,15 @@ when it's used outside the structure's definition.
<rdar://problem/54089342> REPL fails to enforce private(set) on struct property
-->
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

无用的注释可以删除掉


当你编写或扩展一个类型让它遵循一个协议时,你必须确保该类型对协议每一个要求的实现至少与协议的访问级别一致。例如,如果一个 `public` 类型遵循一个 `internal` 协议,那么该类型对协议每一个要求的实现必须至少是 `internal`。

> 注意: Swift 和 Objective-C 一样,协议遵循是全局的——在同一程序中,一个类型不可能用两种不同的方式遵循同一个协议。
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

协议遵循是全局的——
这里的——符号建议更改为句号。

@@ -1409,6 +1103,14 @@ to organize your code,
whether or not your types have private entities.
For example, given the following simple protocol:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

删除原文

The access level for a generic type or generic function is
the minimum of the access level of the generic type or function itself
and the access level of any type constraints on its type parameters.
泛型类型或泛型函数的访问级别是本身的访问级别与其类型参数上的任何类型约束的访问级别中最低的那个。
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

建议更改为:

泛型类型或泛型函数的访问级别取决于泛型类型或泛型函数本身的访问级别,还需结合类型参数的类型约束的访问级别,根据这些访问级别中的最低访问级别来确定。
使用多个子句来代替复杂的长句

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Under Review
Development

Successfully merging this pull request may close these issues.

LanguageGuide / accesscontrol.md ⭐️⭐️⭐️⭐️⭐️
3 participants