This playground includes some extensions that I like to use. You can find examples here and actual implementation is under /Source folder. You can try them with cloning this repository.

/// OptionalExtensions
///
/// Unwraps and returns value of optional property.
/// Returns default value if property is nil.
///
///     let integerValue: Int? = nil
///     let unwrappedValue = integerValue.unwrappedValue(defaultValue: 1)
///     print(unwrappedValue)
///     // prints 1
///
///     let integerValue: Int? = 5
///     let unwrappedValue = integerValue.unwrappedValue(defaultValue: 1)
///     print(unwrappedValue)
///     // prints 5
func unwrappedValue<T>(defaultValue: @autoclosure () -> T) -> T

GitHub

View Github