Last active
September 1, 2018 15:14
-
-
Save kingiol/09e8b30e45d5d30d4dc70ecedcdf997c to your computer and use it in GitHub Desktop.
Can print any object to String
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
infix operator ???: NilCoalescingPrecedence | |
public func ???<T>(optional: T?, defaultValue: @autoclosure () -> String) -> String { | |
switch optional { | |
case let value?: | |
return String(describing: value) | |
case nil: | |
return defaultValue() | |
} | |
} | |
let x = "123" ??? "34" | |
print("x: \(x)") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment