Skip to content

Instantly share code, notes, and snippets.

@Neradoc
Created April 15, 2016 05:22
Show Gist options
  • Save Neradoc/43da69ffd7e1a3e97978ecd5f4407606 to your computer and use it in GitHub Desktop.
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
// 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