Skip to content

Instantly share code, notes, and snippets.

@atomkirk
Created September 23, 2015 16:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save atomkirk/e06f7aad56bc4c9a97a8 to your computer and use it in GitHub Desktop.
Save atomkirk/e06f7aad56bc4c9a97a8 to your computer and use it in GitHub Desktop.
Debug Loggin In Swift
#if DEBUG
func dLog(message: AnyObject, filename: String = __FILE__, function: String = __FUNCTION__, line: Int = __LINE__) {
NSLog("%@", "[\(filename):\(line)] \(function) - \(message)")
}
func uLog(message: AnyObject, filename: String = __FILE__, function: String = __FUNCTION__, line: Int = __LINE__) {
let message = NSString(format: "%@", "\(function) - \(message)") as String
let alertView = UIAlertView(title: "[\(filename):\(line)]", message: message, delegate:nil, cancelButtonTitle:"OK")
alertView.show()
}
#else
func dLog(message: AnyObject, filename: String = __FILE__, function: String = __FUNCTION__, line: Int = __LINE__) { }
func uLog(message: AnyObject, filename: String = __FILE__, function: String = __FUNCTION__, line: Int = __LINE__) { }
#endif
func aLog(message: String, filename: String = __FILE__, function: String = __FUNCTION__, line: Int = __LINE__) {
NSLog("%@", "[\(filename):\(line)] \(function) - \(message)")
}
@atomkirk
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment