@@ -1640,8 +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 erases type information for
1644
- outside a compiler-control statement
1643
+ Builds a partial result that erases type information.
1644
+ You can implement this method to prevent type information
1645
+ from propagating outside a compiler-control statement
1645
1646
that performs an availability check.
1646
1647
1647
1648
For example, the code below defines a simple result builder
@@ -1741,9 +1742,14 @@ into code that calls the static methods of the result builder type:
1741
1742
You can define an overload of ` buildExpression(_:) `
1742
1743
that takes an argument of type ` () ` to handle assignments specifically.
1743
1744
- A branch statement that checks an availability condition
1744
- becomes a call to the ` buildLimitedAvailability(_:) ` method if one is defined.
1745
+ becomes a call to the ` buildLimitedAvailability(_:) ` method,
1746
+ if that method is implemented.
1747
+ If you don't implement ` buildLimitedAvailability(_:) ` ,
1748
+ then branch statements that check availability
1749
+ use the same transformations as other branch statements.
1745
1750
This transformation happens before the transformation into a call to
1746
1751
` buildEither(first:) ` , ` buildEither(second:) ` , or ` buildOptional(_:) ` .
1752
+
1747
1753
You use the ` buildLimitedAvailability(_:) ` method to erase type information
1748
1754
that changes depending on which branch is taken.
1749
1755
For example,
@@ -1818,7 +1824,7 @@ into code that calls the static methods of the result builder type:
1818
1824
1819
1825
To solve this problem,
1820
1826
implement a ` buildLimitedAvailability(_:) ` method
1821
- to erase type information.
1827
+ to erase type information by returning a type that's always available .
1822
1828
For example, the code below builds an ` AnyDrawable ` value
1823
1829
from its availability check.
1824
1830
@@ -1845,11 +1851,6 @@ into code that calls the static methods of the result builder type:
1845
1851
1846
1852
<!-- Comment block with swifttest for the code listing above is after the end of this bulleted list, due to tooling limitations. -->
1847
1853
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
-
1853
1854
- A branch statement becomes a series of nested calls to the
1854
1855
` buildEither(first:) ` and ` buildEither(second:) ` methods.
1855
1856
The statements' conditions and cases are mapped onto
0 commit comments