> For the complete documentation index, see [llms.txt](https://lochiwei.gitbook.io/ios/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://lochiwei.gitbook.io/ios/compiler-errors/cannot-assign-value-of-type-t-to-type-t.md).

# cannot assign value of type 'T' to type 'T'

{% tabs %}
{% tab title="💈範例" %}
{% hint style="danger" %}
⭐ 注意：

下面的 **init** 不能寫成 <mark style="color:red;">**`init<T>`**</mark>，不然會引進「<mark style="color:yellow;">**新的型別參數**</mark> <mark style="color:red;">**`T`**</mark>」（是的，跟「<mark style="color:green;">**舊的型別參數**</mark> <mark style="color:purple;">**`T`**</mark>」名字<mark style="color:red;">**一模一樣**</mark>），然後產生「<mark style="color:red;">**令人傻眼的錯誤訊息**</mark>」🙄：&#x20;

```
⛔ cannot assign value of type 'T' to type 'T'
```

{% endhint %}

```swift
// non-nominal type wrapper
struct NonnominalType<T> {
    let subject: T
}

extension NonnominalType {
    // ⭐ 注意：這裡不能寫成 `init<T>`
    // 不然會引進「新的型別參數 `T`」（是的，跟「舊的型別參數 `T`」
    // 名字一模一樣），然後產生「令人傻眼的錯誤訊息」：
    // 「⛔ cannot assign value of type 'T' to type 'T'」
    init(_ subject: T){
        self.subject = subject
    }
}
```

{% endtab %}

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

* [non-nominal type \`...\` cannot be extended](/ios/compiler-errors/non-nominal-type-...-cannot-be-extended.md)
* [tuple](/ios/swift/type/category/basic/tuple.md) - non-nominal type
  {% endtab %}
  {% endtabs %}
