Use unwrap() on any optional that you expect to always be non-nil, or else crash your App with a more (optional) descriptive debug message with .unwrap(debug:)
On top of that, unwrap also provides a sytactic enhancement to easily unwrap optionals through an under-the-hood Guard Statement.
No More iflet pyramids and Guardlet Towers. only a clean and simple extension to your optionals unwrap
Recieve Rich Debug Information with unwrap(debug:)
Adopt this simple but effective enhancment to your code base Now!
Guardlet tower spotted.
Clean, Succinct, and with more descriptive crashes!
Usage
Call unwrap() on any Optional, optionally giving a debugMessage for debugging purposes:
struct Person {
let name: String
let email: String
init(dictionary: [String: Any]) {
name = dictionary["name"].unwrap(debug: "Unable to find json Element Name") as! String
email = dictionary["email"].unwrap(debug: "Unable to find json Element Email") as! String
}
}
let dictionary = ["ame": "Chris", "email": "chrisbkarani@gmail.com"]
let chris = Person(dictionary: dictionary)
print(chris.name) //Chris
print(chris.email) // chrisbkarani@gmail.com
Another Real-World Example
Without Using Unwrap
class LoginController: UIViewController {
var token: Token?
override func viewDidLoad() {
super.viewDidLoad()
// more code is more bugs
guard let unwrappedToken = token else {
// if this crashes we enter a 'nil' state in our app with no debug information
return
}
LoginService.login(unwrappedToken)
}
}
With Unwrap
class LoginController: UIViewController {
var token: Token?
override func viewDidLoad() {
super.viewDidLoad()
LoginService.login(token.unwrap())
}
}
Sukari
🍯 Powerful, Elegant Syntactical Sugar for Swift 🍯
Description
Enjoy Beutiful Syntactic Enhancements to your swift code base
Simply add Sukari to your initializers
Use
.this{}
to Initialize Swiftly! 🌈Clean up your initialization Code! ✨
Initialize in this way. and and stop repeating yourself! 🚦
Easily Create and Set Value Types 🛠
Add Sugar to your own Types with a little Extension 🔌
Make your code base a little Sweeter 🍭
Unwrap
Unwrap lets you easily require
Optional
values.Use unwrap() on any optional that you expect to always be non-nil, or else crash your App with a more (optional) descriptive debug message with
.unwrap(debug:)
On top of that, unwrap also provides a sytactic enhancement to easily
unwrap
optionals through an under-the-hoodGuard
Statement.if
let
pyramids andGuard
let
Towers. only a clean and simple extension to your optionalsunwrap
unwrap(debug:)
Adopt this simple but effective enhancment to your code base Now!
Guard
let
tower spotted.Clean, Succinct, and with more descriptive crashes!
Usage
Call
unwrap()
on anyOptional
, optionally giving adebugMessage
for debugging purposes:Another Real-World Example
Without Using Unwrap
With Unwrap
Installing
Contributing
Please read CONTRIBUTING.md for details on our code of conduct, and the process for submitting pull requests to us.
Authors
Chris Karani
License
This project is licensed under the MIT License - see the LICENSE.md file for details