File tree 1 file changed +34
-0
lines changed
1 file changed +34
-0
lines changed Original file line number Diff line number Diff line change 5
5
6
6
## Swift 5.9
7
7
8
+ * [ SE-0380] [ ] :
9
+
10
+ ` if ` and ` switch ` statements may now be used as expressions to:
11
+
12
+ * Return values from functions, properties, and closures (either with
13
+ implicit or explicit ` return ` )
14
+ * Throw errors using ` throw `
15
+ * Assign values to variables
16
+ * Declare variables
17
+
18
+ Each branch of the ` if ` or ` switch ` must be a single expression, the value
19
+ of which becomes the value of the overall expression when that branch is
20
+ chosen.
21
+
22
+ ``` swift
23
+ let bullet =
24
+ if isRoot && (count == 0 || ! willExpand) { " " }
25
+ else if count == 0 { " - " }
26
+ else if maxDepth <= 0 { " ▹ " }
27
+ else { " ▿ " }
28
+ ```
29
+
30
+ ``` swift
31
+ public static func width (_ x : Unicode.Scalar) -> Int {
32
+ switch x.value {
33
+ case 0 ..< 0x80 : 1
34
+ case 0x80 ..< 0x0800 : 2
35
+ case 0x0800 ..< 0x1_0000 : 3
36
+ default : 4
37
+ }
38
+ }
39
+ ```
40
+
8
41
* [ #64927 ] [ ] :
9
42
10
43
Swift 5.9 introduces warnings that catch conversions from an inout
@@ -9732,6 +9765,7 @@ using the `.dynamicType` member to retrieve the type of an expression should mig
9732
9765
[SE- 0370 ]: < https: // github.com/apple/swift-evolution/blob/main/proposals/0370-pointer-family-initialization-improvements.md>
9733
9766
[SE- 0376 ]: < https: // github.com/apple/swift-evolution/blob/main/proposals/0376-function-back-deployment.md>
9734
9767
[SE- 0377 ]: < https: // github.com/apple/swift-evolution/blob/main/proposals/0377-parameter-ownership-modifiers.md>
9768
+ [SE- 0380 ]: < https: // github.com/apple/swift-evolution/blob/main/proposals/0380-if-switch-expressions.md>
9735
9769
9736
9770
[#64927 ]: < https: // github.com/apple/swift/issues/64927>
9737
9771
[#42697 ]: < https: // github.com/apple/swift/issues/42697>
You can’t perform that action at this time.
0 commit comments