# Never

## 定義

```swift
// an empty enum
enum Never {}
```

## 重要語錄

> **Never** is an **uninhabited type**, which means that it has **no values**. Or to put it another way, uninhabited types **can’t be constructed**. ... Consider a **function** declared to **return** an **uninhabited type**: Because uninhabited types don’t have any values, the function **can’t return normally**.\
> 👉  [NSHipster](https://nshipster.com/never/#uninhabited-types)

> **Never** is very useful for representing **impossible code**. Most people are familiar with it as the **return type** of functions like **fatalError**, but Never is also useful when working with **generic classes**. For example, a **Result** type might use **Never** for its **Value** to represent something that **always errors** or use **Never** for its **Error** to represent something that **never errors**.\
> \
> An **uninhabited type** can be seen as a **subtype** of **any other type** — if evaluating an **expression** **never** produces a **value**, it doesn’t matter what the type of that expression is. If this were supported by the compiler, it would enable some potentially useful things …\
> 👉   [SE-0215: Conform Never to Equatable and Hashable](https://github.com/apple/swift-evolution/blob/master/proposals/0215-conform-never-to-hashable-and-equatable.md#conform-never-to-equatable-and-hashable)

## 遵循協定

* [`Commands`](https://developer.apple.com/documentation/swiftui/commands)
* [`Comparable`](https://developer.apple.com/documentation/swift/comparable)
* [`CustomizableToolbarContent`](https://developer.apple.com/documentation/swiftui/customizabletoolbarcontent)
* [`Equatable`](https://developer.apple.com/documentation/swift/equatable)
* [`Gesture`](https://developer.apple.com/documentation/swiftui/gesture)
* [`Hashable`](https://developer.apple.com/documentation/swift/hashable)
* [`Scene`](https://developer.apple.com/documentation/swiftui/scene)
* [`ToolbarContent`](https://developer.apple.com/documentation/swiftui/toolbarcontent)
* [`View`](https://developer.apple.com/documentation/swiftui/view) `⭐️`
* [`WidgetConfiguration`](https://developer.apple.com/documentation/swiftui/widgetconfiguration)

## 參考資料

{% tabs %}
{% tab title="🍎 " %}

* Swift  ⟩  Standard Library  ⟩  Debugging & Reflection  ⟩  [Never](https://developer.apple.com/documentation/swift/never)
  {% endtab %}

{% tab title="📘  " %}

* [ ] [How Never Works Internally in Swift](https://swiftrocks.com/how-never-works-internally-in-swift) - SwiftRocks
* [x] [What is the Never return type?](https://www.hackingwithswift.com/example-code/language/what-is-the-never-return-type) - Hacking with Swift
* [x] [Never](https://nshipster.com/never/) - NSHipster ⭐️⭐️⭐️
* [x] [Statement vs Expression](https://blog.kotlin-academy.com/kotlin-programmer-dictionary-statement-vs-expression-e6743ba1aaa0) - Kotlin programmer dictionary
* [x] [Never vs Void](https://stackoverflow.com/a/46902750/5409815) - StackOverflow
* [ ] [Make Never the bottom type](https://forums.swift.org/t/make-never-the-bottom-type/36013) - Swift Forums
* [ ] [Conform Never to Equatable and Hashable](https://github.com/apple/swift-evolution/blob/master/proposals/0215-conform-never-to-hashable-and-equatable.md#conform-never-to-equatable-and-hashable) - Swift Evolution
  {% endtab %}
  {% endtabs %}
