Unwrap 2.1.1

Unwrap 2.1.1

TestsTested
LangLanguage SwiftSwift
License MIT
ReleasedLast Release Sep 2016
SPMSupports SPM

Maintained by muukii, muukii.



Unwrap 2.1.1

Unwrap

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, [email protected]

License

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