Created
April 15, 2016 05:22
-
-
Save Neradoc/43da69ffd7e1a3e97978ecd5f4407606 to your computer and use it in GitHub Desktop.
A variation on logging with emojis, using an empty enum to namespace static funcs
This file contains hidden or 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
// a variation of https://gist.github.com/Neradoc/86b3468a1612f8e1d57db20ab2fab5ae | |
// uses an empty enum as namespace for static functions | |
// otherwise it's pretty much the same | |
enum Log { | |
private static func __log<T>(type:String,_ input:T) { | |
//#if DEBUG | |
print(type,input) | |
//#endif | |
} | |
static func ln(input: String) { __log("β",input) } | |
static func url(input: String) { __log("π",input) } | |
static func error(input: NSError) { __log("β",input) } | |
static func any(input: Any) { __log("βͺ",input) } | |
static func obj(input: AnyObject) { __log("β½",input) } | |
static func date(input: NSDate) { __log("π",input) } | |
} | |
extension Log { | |
static func url(input: NSURL) { __log("π",input.absoluteString) } | |
} | |
// Now here are some examples | |
import Foundation | |
let aString = "This is a string" | |
let url = "http://www.somewhere.com" | |
let nsurl = NSURL(string: url)! | |
let date = NSDate() | |
let error = NSError(domain: "A bad thing happened", code: 101, userInfo: nil) | |
Log.ln(aString) | |
Log.url(url) | |
Log.url(nsurl) | |
Log.date(date) | |
Log.any(["Key":1337]) | |
Log.error(error) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment