Skip to content

Instantly share code, notes, and snippets.

@rickw
Last active June 25, 2017 11:30
Show Gist options
  • Save rickw/cc198001f5f3aa59ae9f to your computer and use it in GitHub Desktop.
Save rickw/cc198001f5f3aa59ae9f to your computer and use it in GitHub Desktop.
Quick log to NSTextView in Swift
extension NSTextView {
func appendText(line: String) {
Async.main {
let attrDict = [NSFontAttributeName: NSFont.systemFontOfSize(18.0)]
let astring = NSAttributedString(string: "\(line)\n", attributes: attrDict)
self.textStorage?.appendAttributedString(astring)
let loc = self.string?.lengthOfBytesUsingEncoding(NSUTF8StringEncoding)
let range = NSRange(location: loc!, length: 0)
self.scrollRangeToVisible(range)
}
}
}
func xlog(logView:NSTextView?, line:String) {
if let view = logView {
view.appendText(line)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment