# result builder transform

[Swift](https://lochiwei.gitbook.io/ios/swift) ⟩ [Attributes](https://lochiwei.gitbook.io/ios/swift/attributes) ⟩ [Result Builders](https://lochiwei.gitbook.io/ios/swift/attributes/result-builders) ⟩

{% tabs %}
{% tab title="⭐️ 重點" %}
{% hint style="warning" %} <mark style="color:red;">**Can’t**</mark> use <mark style="color:purple;">**break**</mark>, <mark style="color:purple;">**continue**</mark>, <mark style="color:purple;">**defer**</mark>, <mark style="color:purple;">**guard**</mark>(👉 ❓), <mark style="color:purple;">**return**</mark>, <mark style="color:purple;">**while**</mark>, <mark style="color:purple;">**do-catch**</mark> in the code (usaully the **body** of a closure) that a <mark style="color:red;">**result builder**</mark> **transforms**.
{% endhint %}

{% hint style="success" %}

* The **transformation** process <mark style="color:red;">**doesn’t change**</mark> <mark style="color:green;">**declarations**</mark> in the code, which lets you use **temporary** <mark style="color:green;">**constants**</mark> and <mark style="color:green;">**variables**</mark> to build up expressions piece by piece.&#x20;
* It also <mark style="color:red;">**doesn’t change**</mark> <mark style="color:purple;">**throw**</mark> statements, <mark style="color:purple;">**compile-time diagnostic**</mark> statements, or <mark style="color:purple;">**closures**</mark> that **contain** a <mark style="color:red;">**return**</mark> statement.
  {% endhint %}

{% hint style="info" %}
An <mark style="color:red;">**assignment**</mark> (=) statement is transformed like an <mark style="color:red;">**expression**</mark>, but is understood to evaluate to <mark style="color:purple;">**`()`**</mark>. You can define an <mark style="color:red;">**overload**</mark> of <mark style="color:purple;">**`buildExpression(_:)`**</mark> that takes an argument of type <mark style="color:purple;">**`()`**</mark> to handle assignments specifically.  👉 [Swift Reference](https://docs.swift.org/swift-book/ReferenceManual/Attributes.html#ID633)
{% endhint %}
{% endtab %}

{% tab title="📘 手冊" %}

* Swift Evolution ⟩ Result Builder ⟩ [result builder transform](https://github.com/apple/swift-evolution/blob/main/proposals/0289-result-builders.md#the-result-builder-transform)
* Swift Reference ⟩ Attributes ⟩ [Declaration Attributes](https://docs.swift.org/swift-book/ReferenceManual/Attributes.html#ID348) ⟩ <mark style="color:red;">**resultBuilder**</mark> ⭐️
  {% endtab %}
  {% endtabs %}
