Swiftpack.co - Package - JohnSundell/Require

✅ Require

CocoaPods Carthage Swift PM Twitter

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:

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: "git@github.com: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 an issue if you need help, if you found a bug, or if you want to discuss a feature request.
  • Open a PR if you want to make some change to Require.
  • Contact @johnsundell on Twitter for discussions, news & announcements about Require.

Github

link
Stars: 301
Help us keep the lights on

Dependencies

Used By

Total:

Releases

2.0.1 - Nov 5, 2017

Require now uses the Swift 4 version of the Swift Package Description API.

2.0.0 - Oct 20, 2017

Require now uses Swift 4 (thanks @basememara!)

1.0.2 - Apr 11, 2017

This release makes Require Linux-compatible by not using NSException on that platform. Thanks to @darthpelo! 🎉

1.0.1 - Apr 7, 2017

This release makes crashes generated from Require work a lot better with crash reporting tools such as Crashlytics, by raising an NSException before calling preconditionFailure().

1.0.0 - Apr 7, 2017

Initial release of Require 🎉