@@ -1640,11 +1640,9 @@ The additional result-building methods are as follows:
1640
1640
or to perform other postprocessing on a result before returning it.
1641
1641
1642
1642
- term ` static func buildLimitedAvailability(_ component: Component) -> Component ` :
1643
- Builds a partial result that propagates or erases type information
1643
+ Builds a partial result that erases type information for
1644
1644
outside a compiler-control statement
1645
1645
that performs an availability check.
1646
- You can use this to erase type information
1647
- that varies between the conditional branches.
1648
1646
1649
1647
For example, the code below defines a simple result builder
1650
1648
that builds an array of integers.
@@ -1743,7 +1741,7 @@ into code that calls the static methods of the result builder type:
1743
1741
You can define an overload of ` buildExpression(_:) `
1744
1742
that takes an argument of type ` () ` to handle assignments specifically.
1745
1743
- A branch statement that checks an availability condition
1746
- becomes a call to the ` buildLimitedAvailability(_:) ` method.
1744
+ becomes a call to the ` buildLimitedAvailability(_:) ` method if one is defined .
1747
1745
This transformation happens before the transformation into a call to
1748
1746
` buildEither(first:) ` , ` buildEither(second:) ` , or ` buildOptional(_:) ` .
1749
1747
You use the ` buildLimitedAvailability(_:) ` method to erase type information
@@ -1830,7 +1828,7 @@ into code that calls the static methods of the result builder type:
1830
1828
func draw () -> String { return content.draw () }
1831
1829
}
1832
1830
extension DrawingBuilder {
1833
- static func buildLimitedAvailability (_ content : Drawable) -> AnyDrawable {
1831
+ static func buildLimitedAvailability (_ content : some Drawable) -> AnyDrawable {
1834
1832
return AnyDrawable (content : content)
1835
1833
}
1836
1834
}
@@ -1847,6 +1845,11 @@ into code that calls the static methods of the result builder type:
1847
1845
1848
1846
<!-- Comment block with swifttest for the code listing above is after the end of this bulleted list, due to tooling limitations. -->
1849
1847
1848
+ Note that the above code compiled before
1849
+ implementing the ` buildLimitedAvailability ` method,
1850
+ as its role is not to enable the ` if #available ` syntax, but to
1851
+ return a type that's always available.
1852
+
1850
1853
- A branch statement becomes a series of nested calls to the
1851
1854
` buildEither(first:) ` and ` buildEither(second:) ` methods.
1852
1855
The statements' conditions and cases are mapped onto
@@ -2222,7 +2225,7 @@ into code that calls the static methods of the result builder type:
2222
2225
func draw() -> String { return content.draw() }
2223
2226
}
2224
2227
-> extension DrawingBuilder {
2225
- static func buildLimitedAvailability(_ content: Drawable) -> AnyDrawable {
2228
+ static func buildLimitedAvailability(_ content: some Drawable) -> AnyDrawable {
2226
2229
return AnyDrawable(content: content)
2227
2230
}
2228
2231
}
0 commit comments