Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/johnsundell/require
Require optional values to be non-nil, or crash gracefully
https://github.com/johnsundell/require
optionals swift xcode
Last synced: 5 days ago
JSON representation
Require optional values to be non-nil, or crash gracefully
- Host: GitHub
- URL: https://github.com/johnsundell/require
- Owner: JohnSundell
- License: mit
- Created: 2017-04-07T16:39:32.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2019-06-18T15:57:33.000Z (over 5 years ago)
- Last Synced: 2024-10-14T01:23:55.410Z (3 months ago)
- Topics: optionals, swift, xcode
- Language: Swift
- Size: 22.5 KB
- Stars: 415
- Watchers: 15
- Forks: 17
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
# ✅ Require
[![CocoaPods](https://img.shields.io/cocoapods/v/Require.svg)](https://cocoapods.org/pods/Require)
[![Carthage](https://img.shields.io/badge/carthage-compatible-4BC51D.svg?style=flat)](https://github.com/Carthage/Carthage)
[![Swift PM](https://img.shields.io/badge/spm-compatible-brightgreen.svg?style=flat)](https://swift.org/package-manager)
[![Twitter](https://img.shields.io/badge/[email protected]?style=flat)](https://twitter.com/johnsundell)Require lets you easily require `Optional` values to be non-`nil`, or crash gracefully.
Sometimes you have optional values in your code that are not really optional, and will cause your
application to enter an undefined state if `nil`. Require makes it easy to avoid such states, by
causing a crash with rich debug information, to enable you to much easier hunt down & fix the bug.## Usage
Call `require()` on any `Optional`, optionally giving a `hint` for debugging purposes:
```swift
class ConfigurationLoader {
func load() -> Configuration {
let data = readJSONFile().require(hint: "Verify that Config.JSON is valid")
let config: Configuration? = try? unbox(data: data)
return config.require()
}
}
```## Installation
**Swift Package Manager:**
Add `.Package(url: "[email protected]:johnsundell/require.git", majorVersion: 1)` to your `Package.swift` file.
**CocoaPods:**
Add `pod "Require"` to your `Podfile`.
**Carthage:**
Add `github "johnsundell/require"` to your `Cartfile`.
**Manual:**
Clone the repo and drag the file `Require.swift` into your Xcode project.
## Help, feedback or suggestions?
- [Open a PR](https://github.com/JohnSundell/Require/pull/new/master) if you want to make some change to Require.
- Contact [@johnsundell on Twitter](https://twitter.com/johnsundell) for discussions, news & announcements about Require.