Skip to content

Instantly share code, notes, and snippets.

@sandinist
Last active April 6, 2016 08:34
Show Gist options
  • Save sandinist/3519238ea141da45298a0e004ddb7df5 to your computer and use it in GitHub Desktop.
Save sandinist/3519238ea141da45298a0e004ddb7df5 to your computer and use it in GitHub Desktop.
debug print for swift
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