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.


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()


Swift Package Manager:

Add .Package(url: "git@github.com:johnsundell/require.git", majorVersion: 1) to your Package.swift file.


Add pod "Require" to your Podfile.


Add github "johnsundell/require" to your Cartfile.


Clone the repo and drag the file Require.swift into your Xcode project.

Help, feedback or suggestions?


Stars: 357
Help us keep the lights on



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 🎉