Skip to content

Instantly share code, notes, and snippets.

@bharath2020
bharath2020 / unwrappedDescription.swift
Last active April 1, 2017 20:31
Optional description
func unwrappedDescription<T>(_ value: Optional<T>) -> String {
guard let value = value else {
return "None."
}
return "\(value)"
}
@bharath2020
bharath2020 / Custom ImplicitOptionalDescription.swift
Created April 1, 2017 20:31
Custom ImplicitOptionalDescription
extension Optional : CustomStringConvertible {
public var description: String {
switch (self) {
case .none:
return "nil"
case let .some(value):
return "\(value)"
}
}
}