Created
November 18, 2017 21:40
-
-
Save ericjames/9a1f0b8d8c96356def490526fe369eb6 to your computer and use it in GitHub Desktop.
Swift 3 - Using a UITextView as a console log
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 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