Skip to content

Instantly share code, notes, and snippets.

@ericjames
Created November 18, 2017 21:40
Show Gist options
  • Save ericjames/9a1f0b8d8c96356def490526fe369eb6 to your computer and use it in GitHub Desktop.
Save ericjames/9a1f0b8d8c96356def490526fe369eb6 to your computer and use it in GitHub Desktop.
Swift 3 - Using a UITextView as a console log
func log(text: String, pauseLog: Bool) {
let newDate = Date()
let dateFormatter = DateFormatter()
dateFormatter.locale = Locale(identifier: "en_US")
dateFormatter.setLocalizedDateFormatFromTemplate("HH:mm:ss")
let displayDate = dateFormatter.string(from: newDate) + ": "
let newLogText = (self.outputText.text ?? "\n") + displayDate + text + "\n"
print(newLogText)
self.outputText.text = newLogText
self.outputText.scrollRangeToVisible(NSMakeRange(self.outputText.text.count - 1,0))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment