Require
Require optional values to be non-nil, or crash gracefully
Install / Use
/learn @JohnSundell/RequireREADME
✅ Require
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 a PR if you want to make some change to Require.
- Contact @johnsundell on Twitter for discussions, news & announcements about Require.
Related Skills
node-connect
342.5kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
85.3kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
342.5kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
qqbot-media
342.5kQQBot 富媒体收发能力。使用 <qqmedia> 标签,系统根据文件扩展名自动识别类型(图片/语音/视频/文件)。
