Skip to content
Require optional values to be non-nil, or crash gracefully
Swift Ruby
Branch: master
Clone or download
JohnSundell Merge pull request #12 from calebkleveter/patch-1
We don't use issues anymore 🎉
Latest commit 02b9fb2 Jun 18, 2019
Type Name Latest commit message Commit time
Failed to load latest commit information.
Require.xcodeproj Disable code coverage to fix app submission with Xcode 9 Oct 1, 2017
.gitignore Generate project with SwiftPlate Apr 7, 2017
.swift-version Bump Podspec to 2.0.0 & add .swift-version file Oct 20, 2017 Add Code of Conduct Nov 5, 2017
Package.swift Use Swift 4 Package Description API Nov 5, 2017 We don't use issues anymore 🎉 May 30, 2019


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: "", 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?

You can’t perform that action at this time.