Created
July 20, 2015 07:31
-
-
Save dfreniche/cc6db49d53899f5d012d to your computer and use it in GitHub Desktop.
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
import Foundation | |
// Not Optional Operator | |
// Useful to print out Optional values without the "Optional" text | |
prefix operator !? {} | |
prefix func !? (any: Any?) -> Any { | |
if let something = any { | |
return something | |
} | |
return "" | |
} | |
var s: String? | |
s = "hello" | |
println("Something \(s)") // Something Optional("hello") | |
println("Something \(!?s)") // Something hello | |
var i: Int? | |
i = 10 | |
println("i \(i)") // i Optional(10) | |
println("i \(!?i)") // i 10 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Tired of printing optional values and seeing all those Optional() in your log files?
Just print saying that something is Not (!) Optional (?) and that's all!