# user

[dev](https://lochiwei.gitbook.io/ios/master) ⟩ [terms](https://lochiwei.gitbook.io/ios/master/term) ⟩ [roles](https://lochiwei.gitbook.io/ios/master/term/roles) ⟩ user&#x20;

{% hint style="success" %} <mark style="color:purple;">使用者</mark>╱*<mark style="color:purple;">user</mark>*╱*<mark style="color:purple;">consumer</mark>*╱*<mark style="color:purple;">client</mark>*\
程式開發中，使用[函數](https://lochiwei.gitbook.io/ios/swift/type/category/basic/func)、[型別](https://lochiwei.gitbook.io/ios/swift/type)定義的人 (或程式碼)。\
:u6307: 通常指「某一段<mark style="color:yellow;">程式碼</mark>」
{% endhint %}

{% tabs %}
{% tab title="💈 範例" %}

```swift
// ⭐️ implementer: 
// 在這裡，`makeCircle` 就是實現者，他決定了返回值的具體型別是 `Circle`，
// 雖然對外只暴露 `some Shape`(使用者只知道返回值是 `some Shape`)。
func makeCircle(radius: Double) -> some Shape {
    return Circle(radius: radius)
}

// ⭐️ user:
// 呼叫 `makeCircle` 的程式碼就是使用者，使用者只知道返回型別符合 Shape 協議，
// 但不知道具體型別是什麼（因為返回值是 some Shape）。
let shape = makeCircle(radius: 5)
```

<pre class="language-swift"><code class="lang-swift">// ⭐️ implementer: 定義型別、函數
// ------------------------------
<strong>protocol MyShape {
</strong>    func area() -> Double
}

struct MyCircle: MyShape {
    var radius: Double
    func area() -> Double { .pi * radius * radius }
}

func makeCircle() -> some MyShape {
    return MyCircle(radius: 10)      // ⭐️ 實現者決定具體型別：`MyCircle`
}

// ⭐️ user: 使用型別、函數
// ------------------------------
let shape = makeCircle()             // ⭐️ 使用者只能知道它是：`some MyShape`
print(shape.area())                  // ⭐️ 可使用 `MyShape` 協議的方法
</code></pre>

{% endtab %}

{% tab title="👥 相關" %}

* :scales: [some-any-generics](https://lochiwei.gitbook.io/ios/swift/type/category/some-any-generics "mention")：實現者與使用者對型別有不同的控制權。
  {% endtab %}

{% tab title="📗 參考" %}

* ChatGPT ⟩ [學習 Swift](https://chatgpt.com/share/675507f6-f118-800e-bbf4-5ca6d40ad646)&#x20;
  {% endtab %}
  {% endtabs %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://lochiwei.gitbook.io/ios/master/term/roles/user.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
