TestsTested | ✗ |
LangLanguage | SwiftSwift |
License | MIT |
ReleasedLast Release | Sep 2016 |
SPMSupports SPM | ✓ |
Syntax sugar for unwrapping while throwing error for nil
With this syntax sugar you can unwrap variables while throwing error for nil. It’s useful in closures/functions with throw.
func unwrap<T: UnwrapProtocol>(object: T, _ error: ErrorType = default) throws -> T.Wrapped
let foo: Int = 3
let bar: Int? = 3
try unwrap(foo) // Compile error
try unwrap(bar) // OK
{ [weak self] in
let _self = try unwrap(self)
}
operation
.doOnNext { [weak self] i
let _self = try unwrap(self)
_self.value = "abc"
}
Unwrap is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod "Unwrap"
muukii, [email protected]
Unwrap is available under the MIT license. See the LICENSE file for more info.