https://github.com/eneko/die
Perform a fatalError with style
https://github.com/eneko/die
Last synced: 3 months ago
JSON representation
Perform a fatalError with style
- Host: GitHub
- URL: https://github.com/eneko/die
- Owner: eneko
- Created: 2018-03-03T04:47:06.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2018-03-03T06:39:37.000Z (over 7 years ago)
- Last Synced: 2025-02-09T07:25:25.532Z (5 months ago)
- Size: 1.95 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# die
Terminating a Swift application with style:
```swift
func die(_ message: @autoclosure () -> String, file: StaticString = #file, line: UInt = #line) -> T {
preconditionFailure("💥 " + message(), file: file, line: line)
}
```## Usage
Application or Playground:
```swift
let name: String? = nil
print(name!)
// Fatal error: Unexpectedly found nil while unwrapping an Optional value
``````swift
let name: String? = nil
print(name ?? die("A girl has no name."))
Fatal error: 💥 A girl has no name: file MyPlayground.playground, line 5
```Swift REPL:
```
1> let name: String? = nil
name: String? = nil
2> print(name!)
Fatal error: Unexpectedly found nil while unwrapping an Optional value
2018-03-02 22:16:27.761699-0800 repl_swift[65869:2477278] Fatal error: Unexpectedly found nil while unwrapping an Optional value
``````
1> let name: String? = nil
name: String? = nil
2> print(name ?? die("A girl has no name."))
Fatal error: 💥 A girl has no name.: file repl.swift, line 6
2018-03-02 22:17:12.308533-0800 repl_swift[65869:2477278] Fatal error: A girl has no name.: file repl.swift, line 6
```## Instalation
Copy the method above and paste it in your code. If you are not fond of the name `die()`, please rename it to something else. You can even use emoji:```swift
print(name ?? 💣("A girl has no name"))
```