Last active
April 6, 2016 08:34
-
-
Save sandinist/3519238ea141da45298a0e004ddb7df5 to your computer and use it in GitHub Desktop.
debug print for 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
func dprint(object: Any?, function: StaticString = #function, file: StaticString = #file, line: UInt = #line) { | |
#if DEBUG | |
let format = NSDateFormatter() | |
format.dateFormat = "yyyy/MM/dd HH:mm:ss.SSS" | |
let encodedFilePath = NSString(string: String(file)).stringByAddingPercentEncodingWithAllowedCharacters(NSCharacterSet.alphanumericCharacterSet())! | |
let fileName = NSURL(string: String(encodedFilePath))!.lastPathComponent! | |
Swift.print("\(format.stringFromDate(NSDate())) \(fileName) [\(line)] \(function): \(object ?? "nil")", terminator: "\n") | |
#endif | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment