by
8,516 31
1
7
283k
0
Top 1% !
Popular
Pearl of Wisdom
Easy-to-find
Specified
Tuned
MultiPlatform
Popularity: 4213rd place
ArchitectureSPARC
InputName2args
InputType0format
InputType1String
InputType2_
InputType3CVarArgType...
Languageswift
MethodNameSWLog
OutputTypefunc

Swift 2: Custom logger that mimics NSLog

Using this initializer, you can easily build a custom logger that mimics NSLog:
Copy Embed Code
<iframe id="embedFrame" style="width:600px; height:300px;"
src="https://www.snip2code.com/Embed/575784/Swift-2--Custom-logger-that-mimics-NSLog?startLine=0"></iframe>
Click on the embed code to copy it into your clipboard Width Height
Leave empty to retrieve all the content Start End
public func SWLog(format: String, _ args: CVarArgType...) { let dateFormatter = NSDateFormatter() dateFormatter.dateFormat = NSDateFormatter.dateFormatFromTemplate( "mm:ss:SSS", options: 0, locale: NSLocale.currentLocale()) let timeString = dateFormatter.stringFromDate(NSDate()) print("\(timeString): " + String(format: format, arguments: args)) }
If you want to be updated about similar snippets, Sign in and follow our Channels

blog comments powered by Disqus