github.com/muukii/Unwrap

let _self = try self.unwrapped()


License
MIT

Documentation

Unwrap

CI Status Version License Platform

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

Usage

let foo: Int = 3
let bar: Int? = 3
try unwrap(foo) // Compile error
try unwrap(bar) // OK

Advanced

{ [weak self] in
    let _self = try unwrap(self)
}
  • RxSwift
operation
    .doOnNext { [weak self] i
        let _self = try unwrap(self)
        _self.value = "abc"
    }    

Requirements

Installation

Unwrap is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod "Unwrap"

Author

muukii, m@muukii.me

License

Unwrap is available under the MIT license. See the LICENSE file for more info.