Last active
June 25, 2017 11:30
-
-
Save rickw/cc198001f5f3aa59ae9f to your computer and use it in GitHub Desktop.
Quick log to NSTextView in Swift
This file contains hidden or 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
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