Skip to content

Instantly share code, notes, and snippets.

@russbishop
Created May 31, 2016 19:52
Show Gist options
  • Save russbishop/4c598a0f9988d70604dde1bc44d450d3 to your computer and use it in GitHub Desktop.
Save russbishop/4c598a0f9988d70604dde1bc44d450d3 to your computer and use it in GitHub Desktop.
Allow use of NSFileHandle with print()
var standardError = NSFileHandle.fileHandleWithStandardError()
print("hi standard error", toStream: &standardError)
extension NSFileHandle: OutputStreamType {
public func write(string: String) {
if let data = string.dataUsingEncoding(NSUTF8StringEncoding, allowLossyConversion: true) {
self.writeData(data)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment