Created
September 23, 2015 16:06
-
-
Save atomkirk/e06f7aad56bc4c9a97a8 to your computer and use it in GitHub Desktop.
Debug Loggin In Swift
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
#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)") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Credit: https://gist.github.com/xmzio/fccd29fc945de7924b71 and @BryanJBryce