Skip to content

Commit 02495bf

Browse files
committed
fix: missing translation
1 parent ebb555b commit 02495bf

File tree

1 file changed

+45
-48
lines changed

1 file changed

+45
-48
lines changed

swift-6-beta.docc/ReferenceManual/Declarations.md

Lines changed: 45 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -583,7 +583,7 @@ func <#function name#>(<#parameters#>) {
583583

584584
```swift
585585
func f(x: Int, y: Int) -> Int { return x + y }
586-
f(x: 1, y: 2) // both x and y are labeled
586+
f(x: 1, y: 2) // x 和 y 都带有标签
587587
```
588588

589589
<!--
@@ -592,7 +592,7 @@ f(x: 1, y: 2) // both x and y are labeled
592592
```swifttest
593593
-> func f(x: Int, y: Int) -> Int { return x + y }
594594
>> let r0 =
595-
-> f(x: 1, y: 2) // both x and y are labeled
595+
-> f(x: 1, y: 2) // x 和 y 都带有标签
596596
>> assert(r0 == 3)
597597
```
598598
-->
@@ -614,8 +614,8 @@ _ <#parameter name#>: <#parameter type#>
614614
在参数名称前加下划线(`_`)可以抑制参数标签。相应的参数在函数或方法调用中必须没有标签。
615615

616616
```swift
617-
func repeatGreeting(_ greeting: String, count n: Int) { /* Greet n times */ }
618-
repeatGreeting("Hello, world!", count: 2) // count is labeled, greeting is not
617+
func repeatGreeting(_ greeting: String, count n: Int) { /* 打招呼 n */ }
618+
repeatGreeting("Hello, world!", count: 2) // count 带有标签,greeting 没有
619619
```
620620

621621
<!--
@@ -656,7 +656,7 @@ func someFunction(a: inout Int) {
656656
```swift
657657
var x = 7
658658
someFunction(&x)
659-
print(x) // Prints "8"
659+
print(x) // 打印 "8"
660660
```
661661

662662
输入输出参数的传递方式如下:
@@ -677,7 +677,7 @@ func someFunction(a: inout Int) {
677677
a += someValue
678678
}
679679

680-
// Error: This causes a runtime exclusivity violation
680+
// 错误:这会导致运行时排他性违规
681681
someFunction(&someValue)
682682
```
683683

@@ -690,7 +690,7 @@ func someFunction(a: inout Int, b: inout Int) {
690690
b += 1
691691
}
692692

693-
// Error: Cannot pass the same value to multiple in-out parameters
693+
// 错误:不能将同一个值传递给多个 in-out 参数
694694
someFunction(&someValue, &someValue)
695695
```
696696

@@ -733,11 +733,11 @@ func someFunction(a: inout Int) -> () -> Int {
733733

734734
```swift
735735
func multithreadedFunction(queue: DispatchQueue, x: inout Int) {
736-
// Make a local copy and manually copy it back.
736+
// 创建一个本地副本,并在函数结束时手动将其复制回去。
737737
var localX = x
738738
defer { x = localX }
739739

740-
// Operate on localX asynchronously, then wait before returning.
740+
// 异步操作 localX,然后在返回之前等待。
741741
queue.async { someMutatingOperation(&localX) }
742742
queue.sync {}
743743
}
@@ -813,7 +813,7 @@ Where are copies implicitly inserted?
813813
`borrowing` 修饰符表示该函数不保留参数的值。在这种情况下,调用者保持对象的所有权,并对对象的生命周期负责。使用 `borrowing` 可以在函数仅暂时使用对象时最小化开销。
814814

815815
```swift
816-
// `isLessThan` does not keep either argument
816+
// `isLessThan` 不会保留任一参数
817817
func isLessThan(lhs: borrowing A, rhs: borrowing A) -> Bool {
818818
...
819819
}
@@ -822,7 +822,7 @@ func isLessThan(lhs: borrowing A, rhs: borrowing A) -> Bool {
822822
如果函数需要保持参数的值,例如,通过将其存储在全局变量中——你可以使用 `copy` 明确地复制该值。
823823

824824
```swift
825-
// As above, but this `isLessThan` also wants to record the smallest value
825+
// 如上所述,但这个 `isLessThan` 还需要记录最小值
826826
func isLessThan(lhs: borrowing A, rhs: borrowing A) -> Bool {
827827
if lhs < storedValue {
828828
storedValue = copy lhs
@@ -836,7 +836,7 @@ func isLessThan(lhs: borrowing A, rhs: borrowing A) -> Bool {
836836
相反,`consuming` 参数修饰符表示该函数拥有该值的所有权,负责在函数返回之前存储或销毁它。
837837

838838
```swift
839-
// `store` keeps its argument, so mark it `consuming`
839+
// `store` 会保留它的参数,因此将其标记为 `consuming`
840840
func store(a: consuming A) {
841841
someGlobalVariable = a
842842
}
@@ -845,16 +845,16 @@ func store(a: consuming A) {
845845
使用 `consuming` 可以在调用者在函数调用后不再需要使用该对象时,最小化开销。
846846

847847
```swift
848-
// Usually, this is the last thing you do with a value
848+
// 通常,这是你对一个值执行的最后一件事
849849
store(a: value)
850850
```
851851

852852
如果在函数调用后继续使用可复制对象,编译器会在函数调用之前自动复制该对象。
853853

854854
```swift
855-
// The compiler inserts an implicit copy here
856-
store(a: someValue) // This function consumes someValue
857-
print(someValue) // This uses the copy of someValue
855+
// 编译器会在这里插入一个隐式副本
856+
store(a: someValue) // 此函数消耗 someValue
857+
print(someValue) // 这里使用的是 someValue 的副本
858858
```
859859

860860
`inout` 不同,`borrowing``consuming` 参数在调用函数时不需要任何特殊标记:
@@ -869,33 +869,31 @@ someFunction(a: someA, b: someB)
869869

870870
```swift
871871
func borrowingFunction1(a: borrowing A) {
872-
// Error: Cannot implicitly copy a
873-
// This assignment requires a copy because
874-
// `a` is only borrowed from the caller.
872+
// 错误:无法隐式复制 a
873+
// 这个赋值操作需要复制,因为 `a` 只是从调用者那里借来的。
875874
someGlobalVariable = a
876875
}
877876

878877
func borrowingFunction2(a: borrowing A) {
879-
// OK: Explicit copying works
878+
// 可以:显式复制是可以的
880879
someGlobalVariable = copy a
881880
}
882881

883882
func consumingFunction1(a: consuming A) {
884-
// Error: Cannot implicitly copy a
885-
// This assignment requires a copy because
886-
// of the following `print`
883+
// 错误:无法隐式复制 a
884+
// 这个赋值操作需要复制,因为后面有 `print`
887885
someGlobalVariable = a
888886
print(a)
889887
}
890888

891889
func consumingFunction2(a: consuming A) {
892-
// OK: Explicit copying works regardless
890+
// 可以:显式复制在这种情况下有效
893891
someGlobalVariable = copy a
894892
print(a)
895893
}
896894

897895
func consumingFunction3(a: consuming A) {
898-
// OK: No copy needed here because this is the last use
896+
// 可以:不需要复制,因为这是最后一次使用
899897
someGlobalVariable = a
900898
}
901899
```
@@ -925,9 +923,9 @@ _ : <#parameter type#>
925923

926924
```swift
927925
func f(x: Int = 42) -> Int { return x }
928-
f() // Valid, uses default value
929-
f(x: 7) // Valid, uses the value provided
930-
f(7) // Invalid, missing argument label
926+
f() // 有效,使用默认值
927+
f(x: 7) // 有效,使用提供的值
928+
f(7) // 无效,缺少参数标签
931929
```
932930

933931
<!--
@@ -1042,7 +1040,7 @@ struct CallableStruct {
10421040
let callable = CallableStruct(value: 100)
10431041
callable(4, scale: 2)
10441042
callable.callAsFunction(4, scale: 2)
1045-
// Both function calls print 208.
1043+
// 两个函数调用都打印 208
10461044
```
10471045

10481046
<!--
@@ -1069,7 +1067,7 @@ call-as-function 的方法和来自 `dynamicCallable` 特性的方法在将多
10691067
定义一个 call-as-function,或者来自 `dynamicCallable` 特性的方法,并不允许你在函数调用表达式以外的任何上下文中将该类型的实例用作函数。例如:
10701068

10711069
```swift
1072-
let someFunction1: (Int, Int) -> Void = callable(_:scale:) // Error
1070+
let someFunction1: (Int, Int) -> Void = callable(_:scale:) // 错误
10731071
let someFunction2: (Int, Int) -> Void = callable.callAsFunction(_:scale:)
10741072
```
10751073

@@ -1149,7 +1147,7 @@ func alwaysThrows() throws {
11491147
func someFunction(callback: () throws -> Void) rethrows {
11501148
do {
11511149
try callback()
1152-
try alwaysThrows() // Invalid, alwaysThrows() isn't a throwing parameter
1150+
try alwaysThrows() // 无效,alwaysThrows() 不是一个抛出参数
11531151
} catch {
11541152
throw AnotherError.error
11551153
}
@@ -1331,9 +1329,9 @@ enum Number {
13311329
case real(Double)
13321330
}
13331331
let f = Number.integer
1334-
// f is a function of type (Int) -> Number
1332+
// f 是一个 (Int) -> Number 的函数类型
13351333

1336-
// Apply f to create an array of Number instances with integer values
1334+
// 应用函数 `f` 来创建一个包含整数值的 `Number` 实例数组
13371335
let evenInts: [Number] = [0, 2, 4, 6].map(f)
13381336
```
13391337

@@ -1757,7 +1755,7 @@ enum MyEnum: SomeProtocol {
17571755

17581756
```swift
17591757
protocol SomeProtocol: AnyObject {
1760-
/* Protocol members go here */
1758+
/* 协议成员写在这里 */
17611759
}
17621760
```
17631761

@@ -1889,7 +1887,6 @@ getter 和 setter 的要求可以通过符合类型以多种方式满足。如
18891887
subscript (<#parameters#>) -> <#return type#> { get set }
18901888
```
18911889

1892-
18931890
下标声明仅声明符合协议的类型所需的最小 getter 和 setter 实现要求。如果下标声明同时包含 `get``set` 关键字,则符合的类型必须实现 getter 和 setter 子句。如果下标声明仅包含 `get` 关键字,则符合的类型必须实现*至少*一个 getter 子句,并且可以选择性地实现一个 setter 子句。
18941891

18951892
在协议声明中声明静态下标要求时,使用 `static` 声明修饰符标记下标声明。符合该协议的结构体和枚举使用 `static` 关键字声明下标,而符合该协议的类则使用 `static``class` 关键字声明下标。为结构体、枚举或类添加协议符合性的扩展使用与其扩展的类型相同的关键字。为静态下标要求提供默认实现的扩展使用 `static` 关键字。
@@ -1912,11 +1909,11 @@ protocol SomeProtocol {
19121909
}
19131910

19141911
protocol SubProtocolA: SomeProtocol {
1915-
// This syntax produces a warning.
1912+
// 此语法会产生警告。
19161913
associatedtype SomeType: Equatable
19171914
}
19181915

1919-
// This syntax is preferred.
1916+
// 推荐使用此语法。
19201917
protocol SubProtocolB: SomeProtocol where SomeType: Equatable { }
19211918
```
19221919

@@ -2072,10 +2069,10 @@ convenience init(<#parameters#>) {
20722069
```swift
20732070
struct SomeStruct {
20742071
let property: String
2075-
// produces an optional instance of 'SomeStruct'
2072+
// 生成一个可选的 `SomeStruct` 实例
20762073
init?(input: String) {
20772074
if input.isEmpty {
2078-
// discard 'self' and return 'nil'
2075+
// 丢弃 'self' 并返回 'nil'
20792076
return nil
20802077
}
20812078
property = input
@@ -2300,7 +2297,7 @@ extension String: TitledLoggable {
23002297
```swift
23012298
let oneAndTwo = Pair(first: "one", second: "two")
23022299
oneAndTwo.log()
2303-
// Prints "Pair of 'String': (one, two)"
2300+
// 打印
23042301
```
23052302

23062303
<!--
@@ -2320,7 +2317,7 @@ func doSomething<T: Loggable>(with x: T) {
23202317
x.log()
23212318
}
23222319
doSomething(with: oneAndTwo)
2323-
// Prints "(one, two)"
2320+
// 打印 "(one, two)"
23242321
```
23252322

23262323
<!--
@@ -2352,15 +2349,15 @@ protocol Serializable {
23522349

23532350
extension Array: Serializable where Element == Int {
23542351
func serialize() -> Any {
2355-
// implementation
2352+
// 实现
23562353
}
23572354
}
23582355
extension Array: Serializable where Element == String {
23592356
func serialize() -> Any {
2360-
// implementation
2357+
// 实现
23612358
}
23622359
}
2363-
// Error: redundant conformance of 'Array<Element>' to protocol 'Serializable'
2360+
// 错误:'Array<Element>' 对协议 'Serializable' 的遵循是多余的
23642361
```
23652362

23662363
<!--
@@ -2402,7 +2399,7 @@ extension String: SerializableInArray { }
24022399

24032400
extension Array: Serializable where Element: SerializableInArray {
24042401
func serialize() -> Any {
2405-
// implementation
2402+
// 实现
24062403
}
24072404
}
24082405
```
@@ -2484,7 +2481,7 @@ extension Array: MarkedLoggable where Element: MarkedLoggable { }
24842481
```swift
24852482
extension Array: Loggable where Element: TitledLoggable { }
24862483
extension Array: Loggable where Element: MarkedLoggable { }
2487-
// Error: redundant conformance of 'Array<Element>' to protocol 'Loggable'
2484+
// 错误:'Array<Element>' 对协议 'Loggable' 的遵循是多余的
24882485
```
24892486

24902487
<!--
@@ -2839,11 +2836,11 @@ Swift 提供五种访问控制级别:open、public、internal、file private
28392836
>
28402837
> *actor-isolation-modifier***`nonisolated`**
28412838
2842-
> Beta 软件:
2839+
> 测试版软件:
28432840
>
28442841
> 本文件包含有关正在开发的 API 或技术的初步信息。此信息可能会更改,按照本文件实施的软件应与最终操作系统软件进行测试。
28452842
>
2846-
> 了解有关使用 [Apple Beta 软件](https://developer.apple.com/support/beta-software/) 的更多信息。
2843+
> 了解有关使用 [Apple 测试版软件](https://developer.apple.com/support/beta-software/) 的更多信息。
28472844
28482845
<!--
28492846
This source file is part of the Swift.org open source project

0 commit comments

Comments
 (0)