Last active
January 19, 2025 19:03
-
-
Save Samasaur1/fc0ac732bde806f5b7d84d6b71d7e20f to your computer and use it in GitHub Desktop.
print to standard error in Swift
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
internal struct FileHandleOutputStream: TextOutputStream { | |
private let fileHandle: FileHandle | |
let encoding: String.Encoding | |
init(_ fileHandle: FileHandle, encoding: String.Encoding = .utf8) { | |
self.fileHandle = fileHandle | |
self.encoding = encoding | |
} | |
mutating func write(_ string: String) { | |
if let data = string.data(using: encoding) { | |
fileHandle.write(data) | |
} | |
} | |
} | |
internal var STDERR = FileHandleOutputStream(.standardError) | |
internal var STDOUT = FileHandleOutputStream(.standardOutput) | |
print("Hello, world!, to: &STDERR) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment