# extension

[Swift](https://lochiwei.gitbook.io/ios/swift) ⟩ [type](https://lochiwei.gitbook.io/ios/swift/type) ⟩ extension

{% hint style="success" %}

{% endhint %}

{% tabs %}
{% tab title="⭐️ 重點" %}
{% hint style="success" %}
Extensions in Swift can:

* Add <mark style="color:red;">**computed**</mark> <mark style="color:orange;">**instance**</mark>/<mark style="color:orange;">**type**</mark> **properties**.
* Define <mark style="color:orange;">**instance**</mark>/<mark style="color:orange;">**type**</mark> <mark style="color:red;">**methods**</mark>.
* Provide new <mark style="color:red;">**initializers**</mark>.
* Define [<mark style="color:red;">**subscripts**</mark>](https://lochiwei.gitbook.io/ios/swift/subscripts).
* Define and use new <mark style="color:red;">**nested types**</mark>.
* Make an existing type <mark style="color:purple;">**conform to**</mark> a [<mark style="color:orange;">**protocol**</mark>](https://lochiwei.gitbook.io/ios/swift/type/category/protocol).
* ([protocol-extensions](https://lochiwei.gitbook.io/ios/swift/type/category/protocol/protocol-extensions "mention")) provide <mark style="color:red;">**default implementations**</mark> or add <mark style="color:red;">**additional functionality**</mark>.
  {% endhint %}
  {% endtab %}

{% tab title="🔴 主題" %}

* [extension-of-nested-type](https://lochiwei.gitbook.io/ios/swift/type/category/nested-types/extension-of-nested-type "mention")
* [extension-of-typealias](https://lochiwei.gitbook.io/ios/swift/type/ext/extension-of-typealias "mention")
  {% endtab %}

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

* Swift ⟩ [Extensions](https://docs.swift.org/swift-book/LanguageGuide/Extensions.html)
  {% endtab %}

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

* can define [nested-types](https://lochiwei.gitbook.io/ios/swift/type/category/nested-types "mention").
  {% endtab %}
  {% endtabs %}
