Skip to content

Instantly share code, notes, and snippets.

@algal
Last active July 27, 2022 06:47
Show Gist options
  • Save algal/0a9aa5a4115d86d5cc1de7ea6d06bd91 to your computer and use it in GitHub Desktop.
Save algal/0a9aa5a4115d86d5cc1de7ea6d06bd91 to your computer and use it in GitHub Desktop.
print to stderr in Swift 3
// known-good: Xcode 8, Swift 3
import Foundation
var standardError = FileHandle.standardError
extension FileHandle : TextOutputStream {
public func write(_ string: String) {
guard let data = string.data(using: .utf8) else { return }
self.write(data)
}
}
print("I am printed to stderr",to:&standardError)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment