|
2 | 2 |
|
3 | 3 | _**Note:** This is in reverse chronological order, so newer entries are added to the top._
|
4 | 4 |
|
| 5 | +## Swift 5.9 |
| 6 | + |
| 7 | +* [SE-0366][]: |
| 8 | + |
| 9 | + The lifetime of a local variable value can be explicitly ended using the |
| 10 | + `consume` operator, forwarding ownership to the surrounding call, assignment, |
| 11 | + or initialization without copying: |
| 12 | + |
| 13 | + ```swift |
| 14 | + var x: [String] = [] |
| 15 | + x.append("apples") |
| 16 | + x.append("bananas") |
| 17 | + x.append("oranges") |
| 18 | + |
| 19 | + process(consume x) // forward the current value, without copying |
| 20 | + |
| 21 | + x = [] // start building a new value |
| 22 | + x.append("broccoli") |
| 23 | + x.append("cauliflower") |
| 24 | + x.append("asparagus") |
| 25 | + ... |
| 26 | + ``` |
| 27 | + |
| 28 | +* [SE-0377][]: |
| 29 | + |
| 30 | + Functions can now declare whether they take value parameters by `borrowing` |
| 31 | + access to a value provided by the caller, or by `consuming` a value that the |
| 32 | + callee is allowed to take ownership of: |
| 33 | + |
| 34 | + ``` |
| 35 | + struct HealthyFoods { |
| 36 | + var values: [String] = [] |
| 37 | +
|
| 38 | + // Ask to `consume` the parameter, since we want to use it |
| 39 | + // to incorporate into our own `values` array |
| 40 | + mutating func add(_ value: consuming String) { |
| 41 | + values.append(value) |
| 42 | + } |
| 43 | + } |
| 44 | + ``` |
| 45 | + |
5 | 46 | ## Swift 5.8
|
6 | 47 |
|
7 | 48 | * [SE-0376][]:
|
@@ -9637,8 +9678,10 @@ using the `.dynamicType` member to retrieve the type of an expression should mig
|
9637 | 9678 | [SE-0358]: <https://github.com/apple/swift-evolution/blob/main/proposals/0358-primary-associated-types-in-stdlib.md>
|
9638 | 9679 | [SE-0362]: <https://github.com/apple/swift-evolution/blob/main/proposals/0362-piecemeal-future-features.md>
|
9639 | 9680 | [SE-0365]: <https://github.com/apple/swift-evolution/blob/main/proposals/0365-implicit-self-weak-capture.md>
|
| 9681 | +[SE-0366]: <https://github.com/apple/swift-evolution/blob/main/proposals/0366-move-function.md> |
9640 | 9682 | [SE-0370]: <https://github.com/apple/swift-evolution/blob/main/proposals/0370-pointer-family-initialization-improvements.md>
|
9641 | 9683 | [SE-0376]: <https://github.com/apple/swift-evolution/blob/main/proposals/0376-function-back-deployment.md>
|
| 9684 | +[SE-0377]: <https://github.com/apple/swift-evolution/blob/main/proposals/0377-parameter-ownership-modifiers.md> |
9642 | 9685 |
|
9643 | 9686 | [#42697]: <https://github.com/apple/swift/issues/42697>
|
9644 | 9687 | [#42728]: <https://github.com/apple/swift/issues/42728>
|
|
0 commit comments